Hi,
I've spent two days trying to implement a "so simple" form. The goal is to upload an image / file using Smartgwt pro and DMI architecture.
I've seen all the posts / samples, but none is complete.
I've an upload form to upload an image. This seems to work fine.
In order to test the solution I've a static variable that stores all my uploaded images within objects. This is ok.
Then, I want to dispklay the uploaded images. I've tried to disply them in aother form via an imageFile datafield type. Not working
Then I've tried to display them in a list grid => not ok.
Here is my DS file :
imageTestDS.ds.xml
Here is my POJO Serializable object :
Here is my upload DMI class
Here is my download DMI class
(Note the commented lines indicating all the "empiric" tests I've done)
The viewFile method is correctly called.
and finally the entry point class
I really tried so many possibilities !!!!
Any help => really working sample would be GREAAAAAAT.
Thanks in advance
I've spent two days trying to implement a "so simple" form. The goal is to upload an image / file using Smartgwt pro and DMI architecture.
I've seen all the posts / samples, but none is complete.
I've an upload form to upload an image. This seems to work fine.
In order to test the solution I've a static variable that stores all my uploaded images within objects. This is ok.
Then, I want to dispklay the uploaded images. I've tried to disply them in aother form via an imageFile datafield type. Not working
Then I've tried to display them in a list grid => not ok.
Here is my DS file :
imageTestDS.ds.xml
Code:
<DataSource ID="imageTestDS" serverType="generic"> <fields> <field name="code" title="Key" type="sequence" primaryKey="true" hidden="true"> </field> <field name="title" title="Title" type="text" length="128" required="false"> </field> <field name="imageTest" title="Test image" type="imageFile" required="false" showFileInline="true"> </field> </fields> <serverObject lookupStyle="new" className="image.UploadImageDMI" /> <operationBindings> <binding operationType="viewFile" serverMethod="viewFile"> <serverObject lookupStyle="new" className="image.DownloadImageDMI" /> </binding> </operationBindings> </DataSource>
Here is my POJO Serializable object :
Code:
import java.io.InputStream; import java.io.Serializable; import java.util.ArrayList; import java.util.List; public class ImageObject implements Serializable{ static List<ImageObject> images; static{ images = new ArrayList<ImageObject>(); } private int code; private String title; private InputStream imageTest; public String getTitle() { return title; } public void setTitle(String unTitle) { title = unTitle; } public InputStream getImageTest() { return imageTest; } public void setImageTest(InputStream unImageTest) { imageTest = unImageTest; } public static List<ImageObject> getImages() { return images; } public int getCode() { return code; } public void setCode(int unCode) { code = unCode; } }
Code:
import java.io.InputStream; import com.isomorphic.datasource.DSRequest; import com.isomorphic.datasource.DSResponse; import com.isomorphic.servlet.ISCFileItem; public class UploadImageDMI { public DSResponse fetch(DSRequest dsRequest) throws Exception { DSResponse dsResponse = new DSResponse(); dsResponse.setData(ImageObject.getImages()); return dsResponse; } public ImageObject add(DSRequest record) throws Exception { ImageObject newImage = new ImageObject(); newImage.setCode(record.getParameter("code") == null ? 0 : (Integer)record.getParameter("codeDemande")); newImage.setTitle((String)record.getFieldValue("title")); ISCFileItem file = record.getUploadedFile("imageTest"); InputStream stream = file.getInputStream(); newImage.setImageTest(stream); ImageObject.getImages().add(newImage); return newImage; } }
(Note the commented lines indicating all the "empiric" tests I've done)
The viewFile method is correctly called.
Code:
import com.isomorphic.datasource.DSRequest; import com.isomorphic.datasource.DSResponse; import com.isomorphic.rpc.RPCManager; public class DownloadImageDMI { public DSResponse viewFile(DSRequest dsRequest, RPCManager rpcManager) throws Exception { DSResponse dsResponse = new DSResponse(); rpcManager.doCustomResponse(); // Not working List r = new ArrayList(); // Not working r.add(ImageObject.getImages().get(0)); // Not working dsResponse.setData(ImageObject.getImages().get(0)); //Not working dsResponse.setData(new FileInputStream( "C:/testImage.png" )); dsResponse.setData(ImageObject.getImages()); return dsResponse; } }
Code:
public class TestImageEntry implements EntryPoint { private ListGrid listImages; private DataSource dataSource; private DynamicForm uploadForm; private IButton saveButton; private DynamicForm getUploadForm(){ if(uploadForm == null){ uploadForm = new DynamicForm(); uploadForm.setDataSource(dataSource); uploadForm.editNewRecord(); } return uploadForm; } DynamicForm viewForm; private DynamicForm getViewForm(){ if(viewForm == null){ viewForm = new DynamicForm(); viewForm.setIsGroup(true); viewForm.setGroupTitle("<B>Images"); viewForm.setDataSource(dataSource); // Also tested with these lines commented => not working ViewFileItem imageShow = new ViewFileItem("imageDemande", "view image"); imageShow.setShowFileInline(Boolean.TRUE); imageShow.setAttribute("editorType", "ViewFileItem"); imageShow.setType("imageFile"); imageShow.setHeight(300); imageShow.setWidth(300); ViewFileItem imageHide = new ViewFileItem("imageDemande", "hide image"); imageHide.setShowFileInline(Boolean.FALSE); imageHide.setAttribute("editorType", "ViewFileItem"); imageHide.setType("imageFile"); imageHide.setHeight(300); imageHide.setWidth(300); viewForm.setItems(imageShow, imageHide); } return viewForm; } private ListGrid getListGrid(){ listImages = new ListGrid(); listImages.setDataSource(dataSource); // Also tested without these comments => not working // ListGridField img = new ListGridField("imageDemande", "list image"); // l.setFields(img); // l.setAutoFetchData(true); return listImages; } public IButton getUploadButton(){ if(saveButton == null){ saveButton = new IButton("Save"); saveButton.setTop(100); saveButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { uploadForm.saveData(new DSCallback() { @Override public void execute(DSResponse unResponse, Object unRawData, DSRequest unRequest) { if(viewForm != null) viewForm.fetchData(); if(listImages != null) listImages.fetchData(); } }); } }); } return saveButton; } public void onModuleLoad() { dataSource = DataSource.get("imageTestDS"); RootPanel rootPanel = RootPanel.get(); VLayout hLayout = new VLayout(); hLayout.setWidth("95%"); hLayout.setHeight("95%"); hLayout.setDefaultResizeBars(LayoutResizeBarPolicy.ALL); hLayout.setDefaultLayoutAlign(VerticalAlignment.TOP); hLayout.addMember(getUploadForm()); hLayout.addMember(getUploadButton()); hLayout.addMember(getViewForm()); hLayout.addMember(getListGrid()); rootPanel.add(hLayout, 20, 20); } }
Any help => really working sample would be GREAAAAAAT.
Thanks in advance
Comment