Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

  • How to read a file which is selected by user?

    Hi,
    I am new to smartgwt, The requirement is, in client side user can select multiple files, upload the files to server and process the files according to some business logics, if file contents some business errors then user must be view an error message in the panel. basically i completed the major parts of this,

    i used
    Code:
    UploadItem
    for file selecting purpose, added some form elements into
    Code:
    DynamicForm()
    , finally i called
    Code:
    submitForm()
    . The problem is, I cant get any response from the server.
    how do i complete that?
    I go through saveData() and submit() methods which has
    Code:
    DSCallBack
    mechanisms. the problem of that is, I cant get the file object in server side
    I have attached my code segements, any of help highly appreciated.

    My form
    Code:
     
        DataSource dataSource = DS.getInstance();     final DynamicForm uploadForm = new DynamicForm();    uploadForm.setDataSource(dataSource);    uploadForm.setWidth(300);    Canvas iFrame = new Canvas("iFrame");     final TextItem uploadTitleItem = new TextItem("title");    uploadTitleItem.setRequired(true);      UploadItem imageItem = new UploadItem("image");    imageItem.setMultiple(true);    imageItem.setRequired(false);     DS.getInstance();    uploadForm.setTarget("iFrame");     ButtonItem saveItem = new ButtonItem("save", "Save");    saveItem.addClickHandler(new ClickHandler() {        public void onClick(ClickEvent event) {            uploadForm.setAction("strut action call"); uploadForm.submitForm();        }    });     uploadForm.setFields(uploadTitleItem, imageItem, saveItem, cancel);
    DS class
    Code:
    public class DS {     private static DS instance = null;      public DS() {         setDataFormat(DSDataFormat.JSON);          setAddDataURL("addaction");          DataSourceTextField title = new DataSourceTextField("title", "title");         DataSourceField image = new DataSourceField("image", FIELD.ANY,"image");         setFields(title, image);     } }
    server operations
    Code:
     
     public String addaction() throws Exception{     try {          [COLOR=#660e7a]File = getFile()[/COLOR][COLOR=#000000];         // business logics      } [/COLOR]catch [COLOR=#000000](Exception e) {         [/COLOR]log[COLOR=#000000].error([/COLOR]"Exception in Support " [COLOR=#000000]+ e);     }      [/COLOR]return SUCCESS[COLOR=#000000]; }[/COLOR]
    how should i send a response to client ?
    or
    if you provide an example for submit(callback) or saveData(callback) with file attachment, also can be helpfull to me
    thanks in advance.
Working...
X