Announcement

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

    Validator + Handler don't work together properly

    Hi all,

    I have following code:
    Code:
    public class MySearchPanel extends ShowcasePanel {
        private DynamicForm form;
    ...
    
        public Canvas getViewPanel() {      
            form = new DynamicForm();
            form.setDataSource(...);
            
            MaskValidator validator = new MaskValidator();
            validator.setMask("^\\s*(.*?)\\s*$");
            validator.setTransformTo("$1");
            
            FormItem cbId = new FormItem("cbId");
            cbId.addChangedHandler(new ChangedHandler() {
                public void onChanged(ChangedEvent event) {
                    System.out.println("cbId - changed handler");
                }
            });
            cbId.setValidators(validator);
            
            form.setFields(cbId);
    
            VLayout layout = new VLayout();
            layout.addMember(form);
            
            IButton myButton = new IButton("validate");
            myButton.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    form.validate();
                }
    
            });
            layout.addMember(myButton);
            
            return layout;
        }
    }
    After changing the value of cbId form field and clicking at validate button twice appears exception popup window and in logs I see:
    Code:
    16:38:46.076 [ERROR] [showcase] Uncaught exception escaped
    
    com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses
        at com.google.gwt.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:214)
        at com.google.gwt.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:103)
        at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:101)
        at com.smartgwt.client.widgets.BaseWidget.fireEvent(BaseWidget.java:66)
        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:597)
        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.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:129)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
        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:214)
        at sun.reflect.GeneratedMethodAccessor19.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        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.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
        at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
        at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
        at java.lang.Thread.run(Thread.java:662)
    Caused by: com.google.gwt.core.client.JavaScriptException: (TypeError): _3.replace is not a function
     fileName: http://127.0.0.1:8080/wep/showcase/sc/modules/ISC_Forms.js?isc_version=8.0.js
     lineNumber: 1653
     stack: ([object Object],[object Object],233,[object Object])@http://127.0.0.1:8080/wep/showcase/sc/modules/ISC_Forms.js?isc_version=8.0.js:1653
    isc_c_Validator_processValidator([object Object],[object Object],233,"mask",[object Object])@http://127.0.0.1:8080/wep/showcase/sc/modules/ISC_Forms.js?isc_version=8.0.js:1687
    isc_Canvas_validateField([object Object],[object Array],233,[object Object],[object Object])@http://127.0.0.1:8080/wep/showcase/sc/modules/ISC_Core.js?isc_version=8.0.js:3764
    isc_DynamicForm_validate()@http://127.0.0.1:8080/wep/showcase/sc/modules/ISC_Forms.js?isc_version=8.0.js:575
    ()@http://127.0.0.1:8080:1102
    @:0
    ([object GWTJavaObject],1179847,[object GWTJavaObject])@http://127.0.0.1:8080/wep/showcase/hosted.html?showcase:56
    ([object Object],(void 0))@http://127.0.0.1:8080:1151
    ((function () {var param = {};var event = __gwt_makeJavaInvoke(1)(null, 2687095, param);__gwt_makeJavaInvoke(1)(selfJ, 1179847, event);var ret = __gwt_makeJavaInvoke(0)(event, 1310726);return !ret;}),[object Object],[object Object])@http://127.0.0.1:8080:34
    @:0
    (null,106,(function () {var param = {};var event = __gwt_makeJavaInvoke(1)(null, 2687095, param);__gwt_makeJavaInvoke(1)(selfJ, 1179847, event);var ret = __gwt_makeJavaInvoke(0)(event, 1310726);return !ret;}),[object Object],[object Object])@http://127.0.0.1:8080/wep/showcase/hosted.html?showcase:56
    ([object Object],(void 0))@http://127.0.0.1:8080:47
    ([object Object],(void 0))@http://127.0.0.1:8080:13
    isc_StatefulCanvas_handleActivate([object Object],(void 0))@http://127.0.0.1:8080/wep/showcase/sc/modules/ISC_Foundation.js?isc_version=8.0.js:321
    isc_StatefulCanvas_handleClick([object Object],(void 0))@http://127.0.0.1:8080/wep/showcase/sc/modules/ISC_Foundation.js?isc_version=8.0.js:323
    isc_c_EventHandler_bubbleEvent([object Object],"click")@http://127.0.0.1:8080/wep/showcase/sc/modules/ISC_Core.js?isc_version=8.0.js:1573
    isc_c_EventHandler_handleClick([object Object])@http://127.0.0.1:8080/wep/showcase/sc/modules/ISC_Core.js?isc_version=8.0.js:1421
    isc_c_EventHandler__handleMouseUp([object MouseEvent],(void 0))@http://127.0.0.1:8080/wep/showcase/sc/modules/ISC_Core.js?isc_version=8.0.js:1408
    isc_c_EventHandler_handleMouseUp([object MouseEvent])@http://127.0.0.1:8080/wep/showcase/sc/modules/ISC_Core.js?isc_version=8.0.js:1399
    isc_c_EventHandler_dispatch(isc_c_EventHandler_handleMouseUp,[object MouseEvent])@http://127.0.0.1:8080/wep/showcase/sc/modules/ISC_Core.js?isc_version=8.0.js:1636
    anonymous([object MouseEvent])@http://127.0.0.1:8080/wep/showcase/sc/modules/ISC_Core.js?isc_version=8.0.js:63
    
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:237)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:129)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeBoolean(ModuleSpace.java:184)
        at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeBoolean(JavaScriptHost.java:35)
        at com.smartgwt.client.widgets.form.DynamicForm.validate(DynamicForm.java)
        at com.wirecard.gwt.wep.client.card.chargeback.search.ChargebackSearchPanel$4.onClick(ChargebackSearchPanel.java:96)
        at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.java:99)
        at com.smartgwt.client.widgets.events.ClickEvent.dispatch(ClickEvent.java:1)
        at com.google.gwt.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:204)
        at com.google.gwt.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:103)
        at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:101)
        at com.smartgwt.client.widgets.BaseWidget.fireEvent(BaseWidget.java:66)
        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:597)
        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.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:326)
        at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:207)
        at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:129)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
        at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
        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:214)
        at sun.reflect.GeneratedMethodAccessor19.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        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.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
        at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
        at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
        at java.lang.Thread.run(Thread.java:662)
    Looks to me as a bug. I spent really a lot of time to reproduce it with a simple example.

    Workarounds found:
    If only validator or only handler is used - works
    If this field isn't connected to any datasource - works
    If instead of DynamicForm is SearchForm used - works

    SmartGWT version: 2.5.2011-03-31-EVAL
    Browsers: IE7, FF 3.6.16

    Cheers,
    Alexey

    #2
    Hi Alexey
    This does sound like a bug - but we're not seeing it on our end.

    The attached code doesn't run as it stands, so we had to flesh it out slightly to make it a running test case (attached below). It seems likely that there's something in the DataSource definition or other code in your version that's responsible. Can you show us your full standalone example, or modify the attached code enough that we can run it and see the problem?

    Thanks

    Code:
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.DataSourceField;
    import com.smartgwt.client.widgets.Canvas;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.SearchForm;
    import com.smartgwt.client.widgets.form.fields.FormItem;
    import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
    import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
    import com.smartgwt.client.widgets.form.validator.MaskValidator;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class ValidatorHandler implements EntryPoint {
        private DynamicForm form;
    
        public Canvas getViewPanel() {      
            form = new DynamicForm();
            
            DataSource testDS = new DataSource();
            DataSourceField cbIdf = new DataSourceField();
            cbIdf.setName("cbId");
            testDS.setFields(cbIdf);
            
            form.setDataSource(testDS);
            
            MaskValidator validator = new MaskValidator();
            validator.setMask("^\\s*(.*?)\\s*$");
            validator.setTransformTo("$1");
            
            FormItem cbId = new FormItem("cbId");
            cbId.addChangedHandler(new ChangedHandler() {
                public void onChanged(ChangedEvent event) {
                    System.out.println("cbId - changed handler");
                }
            });
            cbId.setValidators(validator);
            
            form.setFields(cbId);
    
            VLayout layout = new VLayout();
            layout.addMember(form);
            
            IButton myButton = new IButton("validate");
            myButton.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {
                    form.validate();
                }
    
            });
            layout.addMember(myButton);
            
            return layout;
        }
        @Override
        public void onModuleLoad() {
            getViewPanel().draw();
            
        }
    }

    Comment


      #3
      Hi Isomorphic,

      Thanks for fast reply!
      Seems that field type matters (and I have integer type in my DataSource), just try your code with this line:
      Code:
              cbIdf.setType(FieldType.INTEGER);
      Enter some digits as value into the field and click twice (or more) at 'validate' button. Reproducible in 100% cases in my environment.

      Cheers,
      Alexey

      Comment


        #4
        OK, this usage is now a bit strange because you've got a field being validated as an Integer but then you apply a validator meant for String fields.

        What are you trying to achieve here? Your mask validator seems to be designed to trim off leading and trailing whitespace but the built-in Integer validation behavior already handles this - your additional validator is unnecessary.

        Comment


          #5
          Ok, first thing is: this space trimming validator is intended to be used for each form field which has to be trimmed, independent whether it is string or integer in DataSource. I shouldn't care about this actually.

          Second thing is: it looks like that ANY kind of validatior with transforming doesn't work for integer fields, I tested this with following validator:

          Code:
                  MaskValidator validator = new MaskValidator();
                  validator.setMask("^(\\d*?)0*$");
                  validator.setTransformTo("$1");
          This will trim trailing zeros, maybe nothing from the real life, but just as an example.

          Cheers,
          Alexey

          Comment


            #6
            Ok, we've put in a fix for this - it should hit tomorrow's nightly build

            Comment


              #7
              To clarify, the fix we've put in is going to cause your validator to not result in a exception. Your validator still does nothing because the field is declared as an Integer and hence is already parsed as an integer before your validator runs. Likewise your new validator does nothing. No String-based validator really makes sense on an Integer field.

              Comment


                #8
                Thanks for fixing this! No exception now and the validator works as well.
                Can it be that this is fixed only for EE? In PE (2011-04-12) I still face this problem :(

                Comment


                  #9
                  It's not really possible, given how things about built, for this fix to apply to an Evaluate but not Power build. Check the timestamps of the files in your project to see if you are still using older files.

                  Also, bear in mind, what this is fix does is avoid a crash for some (useless) validators. There would be no behavior change other than avoiding the crash.

                  Comment


                    #10
                    sorry for late answer, in PE it works as well, thx!

                    Cheers,
                    Alexey

                    Comment

                    Working...
                    X