Announcement

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

    SmartGWT 2.4 - handling of primitive Java types attributes

    Hi,
    after updating from SmartGWT 2.2 to 2.4, I've realized a problem with getting attribute values of primitive Java types by method:
    Code:
    RefDataClass.getAttributeAsObject()
    For common types like String it works ok. And also the problem appears only in Debug mode (tested in browser IE9).

    For ex. when try to get value of Boolean attribute by this method, there is an exception thrown:
    Code:
    java.lang.IllegalArgumentException: Something other than a Java object was returned from JSNI method '@com.smartgwt.client.util.JSOHelper::getAttributeAsObject(Lcom/google/gwt/core/client/JavaScriptObject;Ljava/lang/String;)': JS value of type boolean, expected java.lang.Object 	
    at com.google.gwt.dev.shell.JsValueGlue.get(JsValueGlue.java:178) 	
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:271) 	
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91) 	
    at com.smartgwt.client.util.JSOHelper.getAttributeAsObject(JSOHelper.java) 	
    at com.smartgwt.client.core.DataClass.getAttributeAsObject(DataClass.java:207) 	
    at de.usu.s3.web.client.VMClient$1.onChanged(VMClient.java:48) 	
    at com.smartgwt.client.widgets.form.fields.events.ChangedEvent.dispatch(ChangedEvent.java:97) 	
    at com.smartgwt.client.widgets.form.fields.events.ChangedEvent.dispatch(ChangedEvent.java:1) 	
    at com.google.gwt.event.shared.HandlerManager$HandlerRegistry.fireEvent(HandlerManager.java:65) 	
    at com.google.gwt.event.shared.HandlerManager$HandlerRegistry.access$1(HandlerManager.java:53) 	
    at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:178) 	
    at com.smartgwt.client.core.DataClass.fireEvent(DataClass.java:237) 	
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 	
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 	
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 	
    at java.lang.reflect.Method.invoke(Unknown Source) 	
    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.NativeMethodAccessorImpl.invoke0(Native Method) 	
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 	
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 	
    at java.lang.reflect.Method.invoke(Unknown Source) 	
    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(Unknown Source)
    Here is a simple example of code, which reproduces the problem (One form item with aditional boolean attribute. After changing the value, there will be an exception thrown).
    Code:
    		FormItem item = new CheckboxItem("test", "Testing Checkbox");
    		item.setAttribute("testBoolAttr", Boolean.TRUE);
    		
    		item.addChangedHandler(new ChangedHandler() {
    			public void onChanged(ChangedEvent event) {
    				Object tmpObject = event.getItem().getAttributeAsObject("testBoolAttr");
    				SC.say("testBoolAttr: " + tmpObject.toString());
    			}
    		});
    		
    		DynamicForm tmpForm = new DynamicForm();
    		tmpForm.setFields(item);
    		
    		tmpForm.show();
    I know that .getAttributeAsBoolean() method could be used in this case, but this is not an option in our application implementation.
    I just wanted to ask, if there is some change in handling of this primitive Java types, or if it is some kind of bug?

    Thanks for any hints.

    #2
    What are you hoping to receive when you call getAttributeAsObject() and the underlying type is boolean? Are you expecting up-conversion to a java.lang.Boolean, or something else?

    Comment


      #3
      Well our use case is, that we set Object attribute (we needn't know what type it is) and then just get attribute as Object and also we don't care about it's type. The Object could be boolean, integer or whatever...
      This had worked in SmartGWT 2.2.

      After debugging I've found, that method .getAttributeAsObject() calls GWT (we are using 2.2 version) method JsValueGlue.get(), which has a part:
      Code:
      if (value.isWrappedJavaObject()) {
            return type.cast(value.getWrappedJavaObject());
      }
      It seems that in SmartGWT 2.2 the given Object attribute was handled as a wrapped Java object, but in the 2.4 it is not anymore. So the JsValueGlue.get() method then throws llegalArgumentException...

      But again, this is happening only in debug mode. After compiling javascripts it works ok.
      I know this seems to be quite a tricky problem, but it would be greate if you can find some solution.

      Comment


        #4
        Having the same problem. Kind of annoying because we need a generic getter for fields of different types that need to be stored and then copied in another record looping through the attribute list.
        getAttribute(myBoolean) gives back a string ("true" or "false") but setting the stored value again by myBoolean.setAttribute("false") provokes the application to crash, which is in my opinion inconsistent.
        I would expect getAttributeAsObject to return a Boolean.

        Comment


          #5
          Hi,

          Did you ever resolve this? I too would like to pass objects. Variables which are java Objects with setAttribute are javaScriptObjects when we read them again with getAttributeAsObject.

          I would like to be able to pass objects without knowing what type they are.

          Many Thanks,
          Jeni

          Comment

          Working...
          X