Announcement

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

    Unable to restrict FilterBuilder operators

    I'm trying to define the subset of operators allowed for a datasource field using the datasource XML definition, but I'm not having any luck.

    I updated the "itemName" field definition in the sample supplyItem.ds.xml a couple of ways:
    1) using the syntax found elsewhere in the forums
    Code:
            <field name="itemName"    type="text"     title="Item"        length="128"       required="true">
                <validOperators>contains</validOperators>
            </field>
    This generates the following output:
    Code:
    INFO: field: itemID. 
    INFO: field: itemName. 
    ERROR: Unable to load module entry point class com.mySampleApplication.client.MySampleApplication (see associated exception for details). java.lang.ClassCastException: java.lang.String cannot be cast to com.google.gwt.core.client.JavaScriptObject
    	at com.smartgwt.client.util.JSOHelper.getAttributeAsJavaScriptObject(JSOHelper.java)
    	at com.smartgwt.client.util.JSOHelper.getAttributeAsStringArray(JSOHelper.java:317)
    	at com.smartgwt.client.core.DataClass.getAttributeAsStringArray(DataClass.java:124)
    	at com.smartgwt.client.data.DataSourceField.getValidOperators(DataSourceField.java:1232)
    	at com.mySampleApplication.client.MySampleApplication.onModuleLoad(MySampleApplication.java:36)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:601)
    	at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
    	at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
    	at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
    	at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
    	at java.lang.Thread.run(Thread.java:722)
    2) trying to create a "richer" element structure
    Code:
            <field name="itemName"    type="text"     title="Item"        length="128"       required="true">
                <validOperators>
                    <operatorId>contains</operatorId>
                </validOperators>
            </field>
    This generates the following output:
    Code:
    INFO: field: itemID. 
    INFO: field: itemName. 
    ERROR: Unable to load module entry point class com.mySampleApplication.client.MySampleApplication (see associated exception for details). java.lang.ClassCastException: [Lcom.smartgwt.client.types.ValueEnum; cannot be cast to [Lcom.smartgwt.client.types.OperatorId;
    	at com.smartgwt.client.data.DataSourceField.getValidOperators(DataSourceField.java:1232)
    	at com.mySampleApplication.client.MySampleApplication.onModuleLoad(MySampleApplication.java:36)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:601)
    	at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
    	at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
    	at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
    	at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
    	at java.lang.Thread.run(Thread.java:722)
    Here is the code used to test this:
    Code:
        public void onModuleLoad() {
            final DataSource dataSource = DataSource.get("supplyItem");
            DataSourceField[] fields = dataSource.getFields();
            for (DataSourceField field : fields) {
                String fieldName = field.getName();
                GWT.log("field: " + fieldName);
                OperatorId[] validOperators = field.getValidOperators(); // ERROR!
                if (validOperators != null) {
                    for (OperatorId validOperator : validOperators) {
                        GWT.log("operatorId: " + validOperator.getValue());
                    }
                }
            }
            final FilterBuilder filter = new FilterBuilder();
            filter.setDataSource(dataSource);
            
            final VStack layout = new VStack();
            layout.addMember(filter);
    
            layout.draw();
        }
    SmartGWT version: SC_SNAPSHOT-2012-01-19_v8.2p/PowerEdition Deployment 2012-01-19
    Browser: IE 9
    Running in hosted mode.

    Thanks for any insight into the validOperators feature.

    #2
    You should find that the validOperators feature works, in the sense that the FilterBuilder respects the setting.

    As far as trying to fetch it in your own code, it looks like the getter method may not understand a value that comes from XML, however, why do this?

    Comment


      #3
      I did that because the filter builder was not restricting the operators when rendering the controls.
      I'll retest and post the output.

      Comment


        #4
        Here's the updated code:
        Code:
            public void onModuleLoad() {
                final DataSource dataSource = DataSource.get("supplyItem");
                final FilterBuilder filter = new FilterBuilder();
                filter.setDataSource(dataSource);        
                final VStack layout = new VStack();
                layout.addMember(filter);
                layout.draw();
            }
        Here's the output:

        Code:
        ERROR: 17:20:13.330:WARN:FilterClause:isc_FilterBuilder_0_clause:buildValueItemList passed null operator. com.smartgwt.client.core.JsObject$SGWT_WARN: 17:20:13.330:WARN:FilterClause:isc_FilterBuilder_0_clause:buildValueItemList passed null operator
        	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        	at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
        	at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:105)
        	at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
        	at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
        	at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
        	at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
        	at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
        	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.smartgwt.client.widgets.form.FilterBuilder.create(FilterBuilder.java)
        	at com.smartgwt.client.widgets.BaseWidget.getOrCreateJsObj(BaseWidget.java:361)
        	at com.smartgwt.client.widgets.layout.Layout.addMember(Layout.java:1129)
        	at com.mySampleApplication.client.MySampleApplication.onModuleLoad(MySampleApplication.java:36)
        	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        	at java.lang.reflect.Method.invoke(Method.java:601)
        	at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
        	at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
        	at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
        	at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
        	at java.lang.Thread.run(Thread.java:722)
        ERROR: Unable to load module entry point class com.mySampleApplication.client.MySampleApplication (see associated exception for details). com.google.gwt.core.client.JavaScriptException: (TypeError): Unable to get value of the property 'ID': object is null or 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)
        	at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
        	at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
        	at com.smartgwt.client.widgets.form.FilterBuilder.create(FilterBuilder.java)
        	at com.smartgwt.client.widgets.BaseWidget.getOrCreateJsObj(BaseWidget.java:361)
        	at com.smartgwt.client.widgets.layout.Layout.addMember(Layout.java:1129)
        	at com.mySampleApplication.client.MySampleApplication.onModuleLoad(MySampleApplication.java:36)
        	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        	at java.lang.reflect.Method.invoke(Method.java:601)
        	at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
        	at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
        	at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
        	at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
        	at java.lang.Thread.run(Thread.java:722)

        Comment


          #5
          I should note that this is using the syntax of #1 above, found in the forums:
          Code:
                  <field name="itemName"    type="text"     title="Item"        length="128"       required="true">
                      <validOperators>contains</validOperators>
                  </field>

          Comment


            #6
            From what we can see this is a problem with not handling a singular value - it could happen if and only if you defined exactly one validOperator in XML. Can you try multiple operators, using this format:

            Code:
                    <field name="itemName"    type="text"     title="Item"        length="128"       required="true">
                        <validOperators>contains</validOperators>
                        <validOperators>iContains</validOperators>
                    </field>
            .. and confirm that this fixes both the accessor crash and the FilterBuilder behavior?

            Comment


              #7
              With two operators the FilterBuilder renders correctly.
              The accessor still crashes with a ClassCastException.
              Code:
              ERROR: Unable to load module entry point class com.mySampleApplication.client.MySampleApplication (see associated exception for details). java.lang.ClassCastException: [Lcom.smartgwt.client.types.ValueEnum; cannot be cast to [Lcom.smartgwt.client.types.OperatorId;
              	at com.smartgwt.client.data.DataSourceField.getValidOperators(DataSourceField.java:1232)
              	at com.mySampleApplication.client.MySampleApplication.onModuleLoad(MySampleApplication.java:40)
              	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
              	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              	at java.lang.reflect.Method.invoke(Method.java:601)
              	at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
              	at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
              	at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
              	at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
              	at java.lang.Thread.run(Thread.java:722)

              Comment


                #8
                Thanks for confirming. This will be scheduled to be fixed, but fairly low priority (on the assumption that one operator isn't plausible and the accessor anomaly isn't very important).

                If you really need runtime access to validOperators client-side, use getAttributeAsJSArray.

                Comment


                  #9
                  Thanks for the update.

                  Comment

                  Working...
                  X