Announcement

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

    Mapping RadioGroupItem to Boolean value

    Is there a recommended way for setting up a RadioGroupItem displaying user friendly Strings for choices, but using a Boolean as the underlying value? I need a radio button option as the editor type for a ListGridField, and it needs to have 3 options. Each one would map to the 3 possible values for a Boolean - null, true, false.
    I tried setting a value map which would map the Strings to each of these Boolean values, but when I try to assign that valueMap, there's a problem with casting the values between the two types. I am aware of setValueFormatter(), and that may work for translating a data value to display value, but I'm not sure I see a way to translate the user selected String to the Boolean value when a selection is made.

    I'm guessing this isn't related to any particular version of SmartGWT, but I'm using a nightly 9-18 build of SmartGWT 2.5, tested in FF, IE9 and Chrome.

    Thanks

    #2
    What problem are you getting related to "casting the values between the two types" when setting a valueMap? Can you show the code and error message?

    Comment


      #3
      This is the form item I am using as the editor type in the ListGridField:

      Code:
      final RadioGroupItem radioGroupItem = new RadioGroupItem();
      LinkedHashMap<Boolean, String> valueMap = new LinkedHashMap<Boolean, String>();
      valueMap.put(Boolean.valueOf(true), "Approved");
      valueMap.put(Boolean.valueOf(false), "Denied");
      radioGroupItem.setValueMap(valueMap);  <-- exception comes from here
      return radioGroupItem;
      Before we go too far down this road, I'm not sure if this usage of value map would work even without any casting issues. The reason is that I'd like one of the radio choices to set the data value back to null, which wouldn't work in this value map because that would be a null key in the LinkedHashMap. So unless these map parameters could be reversed, I'm not sure I'm on the right track here. Perhaps there's a different approach for achieving this functionality?

      Anyway, this is the exception when I load up this form with the code above, the error in ApprovalItem at line 320 is the line where I'm calling setValueMap().

      java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.String
      at com.smartgwt.client.util.JSOHelper.convertMapToJavascriptObject(JSOHelper.java:869)
      at com.smartgwt.client.widgets.form.fields.FormItem.setAttribute(FormItem.java:3721)
      at com.smartgwt.client.widgets.form.fields.FormItem.setValueMap(FormItem.java:4136)
      at com.---.gae.client.gwt.ApprovalItem$3.getEditor(ApprovalItem.java:320)
      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: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.google.gwt.core.client.impl.Impl.apply(Impl.java)
      at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
      at sun.reflect.GeneratedMethodAccessor33.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: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.BaseWidget.getInnerHTML(BaseWidget.java)
      at sun.reflect.GeneratedMethodAccessor45.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: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.BaseWidget.getInnerHTML(BaseWidget.java)
      at sun.reflect.GeneratedMethodAccessor45.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: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.invokeNativeVoid(ModuleSpace.java:289)
      at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
      at com.smartgwt.client.widgets.Canvas.show(Canvas.java)
      at com.---.gae.client.gwt.forms.App$4.onNewApp(App.java:298)
      at com.---.gae.client.gwt.forms.AppFactory$1.onNewDataSource(AppFactory.java:28)
      at com.---.gae.client.gwt.---DS$1.onReceivedEntityInfo(---DS.java:52)
      at com.tempusnova.lib.gwt.BaseDS$10.execute(BaseDS.java:1442)
      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: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.google.gwt.core.client.impl.Impl.apply(Impl.java)
      at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
      at sun.reflect.GeneratedMethodAccessor33.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:172)
      at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
      at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
      at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
      at java.lang.Thread.run(Thread.java:619)

      Comment


        #4
        Using the string equivalents for booleans ("true" / "false") should work here. However it's not clear what you meant about a null key - are you trying to do a 3-state field (true/false/unset) or are you trying to store false as null? Have you see dataSourceField.sqlStorageStrategy?

        Comment


          #5
          I am trying to do a 3-state field, where the value can be switched between true/false/unset. The null key would have been in the valueMap for the underlying data value corresponding to one of the choices in the radio group (picking a certain option in the radio group would unset the field value).
          I am not using SmartGWT server so I don't believe I have sqlStorageStrategy available.

          Comment


            #6
            Without any information on which server integration strategy you're using, what we can tell you is that the simplest thing is probably to declare this as a "text" field, not a boolean field, use 3 string values for the values (no null) and if you intended to store null in your server-side code, do the translation on the server.

            This is the safest route since we know nothing about how you're talking to the server and some messaging formats (eg XML) make it tricky to make and preserve the distinction between explicit null as a value, as opposed to empty string, as opposed to just element not present.

            Comment


              #7
              Thanks, I'll go that route and translate the strings instead of trying to create a real null value.

              Comment

              Working...
              X