Announcement

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

    ValuesManager.getValue()

    Migrating from SmartGWT 4.1 to SmartGWT 6.0
    GWT 2.8.0-beta1

    I have some code that sets a value on a ValuesManager that is a JsArray.
    I used to be able cast the Object returned from ValuesManager.getValue in the following way
    Code:
    Object o = valuesManager.getValue(arrayName);
    if(o != null)
         JsArray array = ((JavaScriptObject) o).cast();
    However after migrating to SmartGWT 6.0 I get a ClassCastException and in order to avoid this exception I am required to use the following code
    Code:
    Object[] objects = (Object[]) valuesManager.getValue(arrayName);
    if(objects != null) {
         JsArray array = JavaScriptObject.createArray().cast();
         for(Object object : objects)
              array.push((JavaScriptObject) object);
    }
    Is this change by design? It is rather painful to have to convert from Object[] to JsArray and will have a large impact on our code. If even it would allow being cast as JavaScriptObject[] it would be simpler to handle this issue, but attempting to do so also causes a ClassCastException.

    #2
    No, this doesn't look to be a by-design change.

    Does this happen if you use a non-beta version of GWT?

    Is it only in certain modes (eg only classic DevMode)?

    What's in the JSArray? Complete code for construction and round-tripping through the ValuesManager would be clearest.

    Comment


      #3
      This happens both as compiled javascript and in super dev mode. The data is JSO wrapper for data delivered from the server from a datasource. In this partiuclar instance it is a table of country codes.

      Code:
           public class CountryCodeWrapper extends JavaScriptObject implements CountryCodeLookup
      {
          protected CountryCodeWrapper()
          {
          }
      
          @Override
          @UnsafeNativeLong
          public final native long getId() /*-{
              return this.id;
           }-*/;
      
          public final native Long getIdAsLong() /*-{
              return this.id == undefined ? null : @java.lang.Long::valueOf(Ljava/lang/String;)(this.id.toString());
          }-*/;
      
          @Override
          @UnsafeNativeLong
          public final native void setId(long id) /*-{
              this.id = id;
           }-*/;
      
          @Override
          public final native String getCode() /*-{
              return this.code;
           }-*/;
      
          @Override
          public final native void setCode(String code) /*-{
              this.code = code;
           }-*/;
      
          @Override
          public final native String getCountryName() /*-{
              return this.countryName;
           }-*/;
      
          @Override
          public final native void setCountryName(String countryName) /*-{
              this.countryName = countryName;
           }-*/;
      
          @Override
          public final native boolean isDefaultLookup() /*-{
              return this.defaultLookup;
           }-*/;
      
          @Override
          public final native void setDefaultLookup(boolean defaultLookup) /*-{
              this.defaultLookup = defaultLookup;
           }-*/;
      
          public final CountryCodeWrapper copy() {
              CountryCodeWrapper copy = CountryCodeWrapper.createObject().cast();
              copy.setId(getId());
              copy.setCode(getCode());
              copy.setCountryName(getCountryName());
              copy.setDefaultLookup(isDefaultLookup());
              return copy;
          }
      }
      I cannot speak to whether this behavior is similar with other versions of GWT because part of our project will only compile with GWT 2.8

      Comment


        #4
        You don't appear to have given us a standalone test case, as is outlined in the Debugging Overview, or the details requested above - the "complete code for construction and round-tripping through the ValuesManager." At a minimum, we'd like to see the code setting the value(s) that you want to get back as a JSArray.

        Comment

        Working...
        X