Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Ext User
    Join Date
    May 2009
    Posts
    3
    Vote Rating
    0
    raimon@extjs is on a distinguished road

      0  

    Default FormPanel and UploadField do not fire callback on completion

    FormPanel and UploadField do not fire callback on completion


    Hi, i am using FormPanel together with FileUploadField for uploading a file to a regular servlet (not a gwt service). this all works correctly, that is, the file is selected and uploaded to the servlet. what is missing however is the option of evaluating the response from the servlet. Formpanel does not get an Events.Submit event so it is impossible a) to detect when the request has completed and b) to give some kind of feedback on the cleint when smthg goes wrong. On the other side, enabling a listener for Events.BeforeSubmit works fine. The new gwt 1.6 has a file upload mechanism with callback functions in error case and normal response. i was wondering if u are using this options at all. here is some code on what im doeing

    Code:
    protected void onRender(Element parent, int index) {
            super.onRender(parent, index);
            setStyleAttribute("margin", "10px");
    
            final FormPanel panel = new FormPanel();
            panel.setHeaderVisible(false);
            panel.setFrame(false);
            panel.setBorders(false);
            panel.setAutoWidth(true);
            panel.setAction(GWT.getModuleBaseURL() + "profileupload");
            panel.setEncoding(Encoding.MULTIPART);
            panel.setMethod(Method.POST);
            panel.setButtonAlign(HorizontalAlignment.LEFT);
            panel.setWidth(350);
            
            // THIS DOES NOT WORK ie handler is not called on completion
            panel.addListener(Events.Submit, new Listener<FormEvent>() {
    
                @Override
                public void handleEvent(FormEvent be) {
                    log("UploadEvent " + be.getEvent() + " " + be.getResultHtml());
                }
                
            });
            
            // THIS WORKS
            panel.addListener(Events.BeforeSubmit, new Listener<FormEvent>(){
                @Override
                public void handleEvent(FormEvent be) {
                    log("beforeSubmit event");
                }
                
            });
                    
            TextField<String> profilename = new TextField<String>();
            profilename.setAllowBlank(false);
            profilename.setName("profilename");
            profilename.setFieldLabel("Profilname");
            panel.add(profilename);
            
            FileUploadField uploadfile = new FileUploadField();
            uploadfile.setAllowBlank(false);
            uploadfile.setFieldLabel("File");
            uploadfile.setName("profile");
            uploadfile.setAutoWidth(true);
            panel.add(uploadfile);
    
            Button uploadbtn = new Button("Uploaden", new SelectionListener<ButtonEvent>() {
    
                public void componentSelected(ButtonEvent ce) {
                    if (!panel.isValid()) {
                        return;
                    }
                    panel.submit();
                }
            });
            panel.addButton(uploadbtn);
            add(panel);
            
        }
    the servlet is just a plain servlet which return some data using the response request as "text/html"

    raimon

  2. #2
    Sencha User
    Join Date
    Apr 2008
    Posts
    133
    Vote Rating
    0
    FireGlow is on a distinguished road

      0  

    Default


    There is such an event at least at 1.2.... And I saw something similar in the 2.x API! Kind of own listener:
    Events:BeforeSubmit : FormEvent(this)
    Fires before the form is submitted. Only applies when using HTML submits. Listeners can cancel the action by calling BaseEvent.setCancelled(boolean).
    • formPanel : this
    Submit : FormEvent(this, resultHtml)
    Fires after the form has been submitted. Only applies when using HTML submits.
    • formPanel : this
    • resultHtml : the response html
    this.addListener(Events.Submit, submitListener);

    Code:
        private Listener<FormEvent> submitListener = new Listener<FormEvent>() {
    
        public void handleEvent(FormEvent be) {
            //TODO: doesn'T make sense to put a space after the resultHTML! but is needed!
            if (be.resultHtml.compareTo("success ")==0) {
            Dispatcher.get().dispatch(new EHRflexEvent<ArchetypeDataModel>(EHRflexEventType.ARCHETYPE_IMPORT_SUCCESSFUL, null));
            } else if (be.resultHtml.equals("update ")) {
            Dispatcher.get().dispatch(new EHRflexEvent<ArchetypeDataModel>(EHRflexEventType.ARCHETYPE_IMPORT_ALREADY_EXISTS, null));
            } else {
            Dispatcher.get().dispatch(new EHRflexEvent<ArchetypeDataModel>(EHRflexEventType.ARCHETYPE_IMPORT_FAILED, null));
            }
    
        }
        };
    In the servlet you can just add a responsetext with the io.writer

  3. #3
    Ext User
    Join Date
    May 2009
    Posts
    3
    Vote Rating
    0
    raimon@extjs is on a distinguished road

      0  

    Default


    hi, thanks for your post and yes, this is also what i thought should be working and is not. i mean that after registering and event for the form posting on Events.Submit, the callback ie. handler is not being called at all. i'm testing currently on gxt2-m1.

    raimon

  4. #4

Thread Participants: 2