Announcement

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

    SelectItem setValue () / getValue () type matching

    Using:
    SmartGWT v8.3d_2012-10-22/LGPL Development Only (built 2012-10-22)
    FF 6.0.2

    I initialize a SelectItem with a LinkedHashMap<String, String>:
    Code:
        valueMap.put ("1", "Value 1");
        valueMap.put ("2", "Value 2");
    When I call selectItem.setValue (2) (type = int and not String), this is what I get when I call getValue ():
    Code:
    00:03:02.107 [INFO] selectItem.getValue (): null
    00:03:02.107 [INFO] selectItem.getValueAsString (): 2
    When I call selectItem.setValue ("2") (type = String, matching the valueMap), this is what I get when I call getValue ():
    Code:
    00:04:11.975 [INFO] selectItem.getValue (): 2
    00:04:11.975 [INFO] selectItem.getValueAsString (): 2
    Test case:
    Code:
    import java.util.LinkedHashMap;
    
    import com.smartgwt.client.widgets.form.fields.SelectItem;
    import com.smartgwt.client.widgets.form.fields.SubmitItem;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.events.SubmitValuesHandler;
    import com.smartgwt.client.widgets.form.events.SubmitValuesEvent;
    import com.smartgwt.client.widgets.layout.HLayout;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.core.client.GWT;
    
    public class SelectItemGetValue implements EntryPoint {
    
      /**
       * The EntryPoint interface
       */
      public void onModuleLoad () {
    
        // add a SelectItem with data sorted in order c/b/a
        // this SelectItem properly respects the LinkedHashMap order c, b, a
        final LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String> ();
        valueMap.put ("1", "Value 1");
        valueMap.put ("2", "Value 2");
    
        final SelectItem selectItem = new SelectItem ();
        selectItem.setTitle ("selectItem");
        selectItem.setValueMap (valueMap);
    
        // when calling selectItem.setValue (2);
        // 00:03:02.107 [INFO] selectItem.getValue (): null
        // 00:03:02.107 [INFO] selectItem.getValueAsString (): 2
        
        // when calling selectItem.setValue ("2");
        // selectItem.setValue ("2");
        // 00:04:11.975 [INFO] selectItem.getValue (): 2
        // 00:04:11.975 [INFO] selectItem.getValueAsString (): 2
    
        // form
        final SubmitItem submitItem = new SubmitItem ();
        final DynamicForm form = new DynamicForm ();
        form.setWrapItemTitles (false);
        form.setFields (selectItem, submitItem);
        form.addSubmitValuesHandler (new SubmitValuesHandler () {
          public void onSubmitValues (final SubmitValuesEvent event) {
            GWT.log ("selectItem.getValue (): " + selectItem.getValue ());
            GWT.log ("selectItem.getValueAsString (): " + selectItem.getValueAsString ());
          }
        });
    
        // display
        final HLayout mainLayout = new HLayout ();
        mainLayout.setWidth100 ();
        mainLayout.setHeight100 ();
        mainLayout.addMember (form);
        mainLayout.draw ();
      }
    }
    It seems that for getValue () to work, with SmartGWT 3.0p-2012-04-26 I could call either selectItem.setValue (2) or selectItem.setValue ("2"), but with 3.1d-2012-10-22 I need to call selectItem.setValue ("2").

    In other words, the type needs to match.
    Is this by design?

    #2
    No this isn't by design - it was an unintended side effect of a different change.
    Thanks for the clear test case - we've now fixed this. The change will show up in the next 8.3d build (Oct 30 or greater)

    Regards
    Isomorphic Software

    Comment


      #3
      Confirmed with SmartGWT 3.1d:
      v8.3d_2012-10-30/LGPL Development Only (built 2012-10-30)

      Comment


        #4
        I'm facing the same issue but with Record instead of int.

        However my selectItem has value map of <Record, String>,
        I have to set value like this:
        selectItem.setValue(myRecord.toString())

        Setting value just as record selectItem.setValue(myRecord) causes getValue to return null.

        Using:
        SmartClient Version: v9.0_2013-07-03/LGPL Development Only (built 2013-07-03)
        FF: 26.0

        Comment


          #5
          Record is not a valid type for the left-hand value of a valueMap (it's basically just being converted to a String via toString()).

          What you might want is the dataSourceField.foreignKey / dataSourceField.includeFrom/optionDataSource functionality, which allows you to select related records and store their primaryKey values. See the docs for details.

          Comment

          Working...
          X