I'm using this class to Upload some files. I'm using smartGwt forms because 
they have a nice look & feel. As you can see i'm using JSNI to add the 
multiple attribute to the upload item. This works fine when i'm using one 
Form for one View. But when i have more then one Form on the view i'm 
getting an exception! All forms are initiated and added at the same time, 
when i have more then one form!  

public class GngsUploadForm extends DynamicForm {

    private UploadItem uploadItem = new UploadItem();
    
    private void initForm(final boolean multiple) {
        this.setTarget("fileUploadiFrame");
        this.setEncoding(Encoding.MULTIPART);
        this.setAction(GWT.getModuleBaseURL() +"singleFileUploadServlet");
        

        final String randomUploadItemName = Long.toString(new 
Date().getTime()); 
        uploadItem.setName(randomUploadItemName);
        uploadItem.setTitle("File: ");
        uploadItem.setRequired(true);
        
        super.setFields(uploadItem);        
        
        Scheduler.get().scheduleDeferred(new Command(){
            @Override
            public void execute(){
                if(!randomUploadItemName.equals("") && multiple) {
                    setMultiple(randomUploadItemName);
                }
            }
        });    
    }
    
    /**
     * 
     */
    public GngsUploadForm(GngsUploadListener listener, boolean multiple) {
        super();
        
        initForm(multiple);
        
        if(listener != null)
            initComplete(listener);
    }

    /**
     * @param jsObj
     */
    public GngsUploadForm(JavaScriptObject jsObj, GngsUploadListener 
listener, boolean multiple) {
        super(jsObj);

        initForm(multiple);        
        
        if(listener != null)
            initComplete(listener); 
    }
    
    @Override
    public void setFields(FormItem... fields) {
        FormItem[] newFields = new FormItem[fields.length+1];
        
        newFields[0] = uploadItem;
        
        for(int i = 1; i < fields.length+1; i++) {
            newFields[i] = fields[i-1];
        }
        
        super.setFields(newFields);
    }
    
    /*
     * if true the uploadItem is required
     * if false the uploadItem is not required
     * default: true
     * @param 
     */
    public void setUploadFieldRequired(boolean uploadItemRequired) {
        uploadItem.setRequired(false);
    }
    
    private native void initComplete(GngsUploadListener listener) /*-{
       $wnd.uploadComplete = function (filename) {
               
[email protected]::uploadComplete(Ljava/lang/String;)(filename);
       };
    }-*/;
    
    private native void setMultiple(String randomUploadItemName) /*-{
        var newAttr= document.createAttribute('multiple');
        newAttr.nodeValue='multiple';
        
$wnd.document.getElementsByName(randomUploadItemName)[0].setAttributeNode(newAttr);
 

    }-*/;    
}

Exception: 

15:09:20.405 [ERROR] [gngs] Uncaught exception escaped
com.google.gwt.core.client.JavaScriptException: (TypeError): 
$wnd.document.getElementsByName(randomUploadItemName)[0] is undefined
    at 
com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:248)
    at 
com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
    at 
com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
....

i don't know why i'm getting this exception :( I hope someone can help me!

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/x9uqYxs4eaoJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to