Announcement

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

    Closing Window upon DynamicForm submission

    Hi there,

    I've been struggling with this and I think I might have hit a bug...

    I have a DynamicForm which is placed on a Window. Now, when the user submits the form, the window should be destroyed.

    When I have this the form submits fine, but the window doesn't close (obviously):
    Code:
    final Window winModal = new Window();
    winModal.setIsModal(true);
    
    final DynamicForm form = new DynamicForm();
    form.setDataSource(aDataSource);
    form.setUseAllDataSourceFields(true);
    
    SubmitItem submitButton = new SubmitItem("Save");
    
    form.setItems(submitButton);
    winModal.addItem(form);
    winModal.show();
    But when I try this the form doesn't validate (I could do that myself of course), it closes the Window eventually BUT I get a weird error message in my console (posted below):
    Code:
    final Window winModal = new Window();
    winModal.setIsModal(true);
    
    final DynamicForm form = new DynamicForm();
    form.setDataSource(aDataSource);
    form.setUseAllDataSourceFields(true);
    
    ButtonItem submitButton = new ButtonItem("Save");
    submitButton
    		.addClickHandler(new com.smartgwt.client.widgets.form.fields.events.ClickHandler() {
    				public void onClick(
    					com.smartgwt.client.widgets.form.fields.events.ClickEvent event) {
    				form.submit();
    				winModal.destroy();
    				}
    		});
    
    form.setItems(submitButton);
    winModal.addItem(form);
    winModal.show();
    And the error:
    Code:
    00:00:23,297 [ERROR] Uncaught exception escaped 
    com.google.gwt.core.client.JavaScriptException: (TypeError): Cannot call method '$49z' of null
     stack: TypeError: Cannot call method '$49z' of null
        at Object.anonymous (eval at Function)
        at Object.fireCallback (http://localhost:8888/nl.kees.help.ModuleTest/sc/modules/ISC_Core.js:270:44)
        at Object.fireCallback (http://localhost:8888/nl.kees.help.ModuleTest/sc/modules/ISC_Core.js:362:60)
        at Object.$38b (http://localhost:8888/nl.kees.help.ModuleTest/sc/modules/ISC_DataBinding.js:483:14)
        at Object.processResponse (http://localhost:8888/nl.kees.help.ModuleTest/sc/modules/ISC_DataBinding.js:337:6)
        at [object Object].<anonymous> (unknown source)
        at __gwt_jsInvoke (http://localhost:8888/nl.kees.help.ModuleTest/hosted.html?nl_kees_help_ModuleTest:70:35)
        at eval at eval (native v8natives.js:132:1)
        at XMLHttpRequest.<anonymous> (unknown source)
        at unknown source
     type: non_object_property_call
     arguments: $49z,
     __gwt_ObjectId: 187
    	at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:195)
    	at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
    	at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
    	at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:264)
    	at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    	at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    	at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:188)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:592)
    	at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    	at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    	at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
    	at com.google.gwt.dev.shell.BrowserChannel.reactToMessages(BrowserChannel.java:1668)
    	at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:401)
    	at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222)
    	at java.lang.Thread.run(Thread.java:595)

    Can anyone tell me how to correctly submit the form AND close the window?

    Regards,

    Kees.

    #2
    Try calling winModal.destroy(); from within a DeferredCommand

    Comment


      #3
      thanks, that helped me finding the right solution.

      However, a DeferredCommand alone didn't do the trick. I would still get the JS error posted in my first post.

      What I ended up doing is call the DeferredCommand in the callback of the savedata like so:

      Code:
      form.addSubmitValuesHandler(new SubmitValuesHandler() {
      
      			public void onSubmitValues(SubmitValuesEvent event) {
      				if (form.validate()) {
      					form.saveData(new DSCallback() {
      						public void execute(DSResponse response,
      								Object rawData, DSRequest request) {
      							DeferredCommand.addCommand(new Command() {
      								public void execute() {
      									winModal.destroy();
      								}
      							});
      						}
      					});
      				}
      			}
      		});
      Hope this helps anyone :)

      Comment


        #4
        Great help mate,
        But since its 2012 almost...

        With the new GWT/smartGWT,
        we must use
        Scheduler.get().scheduleDeferred(new Command() {

        @Override
        public void execute() {
        wnd.destroy();

        }
        });

        instead

        Hope this helps whoever is still using smartgwt out there... :)

        Comment


          #5
          It actually does, since I had a similar error :-)

          And yes, still happily using Smart GWT.

          Comment


            #6
            What's the advantage of using the deferred command over the callback?
            When will the define command execute in the deferred example?

            Comment

            Working...
            X