Announcement

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

    How to get the value from TextItem?

    TextItem.getValue () seems to always return whatever was set via TextItem.setValue ().
    TextItem.getDisplayValue () seems to return what the user sees on the screen...

    So what method should I use to get the value from a TextItem?
    And if anybody cares to explain, why the current behavior?

    SmartGWT or SmartClient version and browser version(s) involved;
    SmartGWT 2.3-2010-09-30
    Gwt 2.0.3
    IE 6.0.2900.5512
    Chrome 7.0.517.24

    Code:
    import com.smartgwt.client.widgets.form.fields.FormItem;
    import com.smartgwt.client.widgets.form.fields.TextItem;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.layout.VLayout;
    import com.smartgwt.client.widgets.IButton;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.core.client.GWT;
    
    public class TextItemGetValueReturnsNull implements EntryPoint {
    
      /**
       * The EntryPoint interface
       */
      public void onModuleLoad () {
    
        // create a TextItem with an initial value set
        final FormItem textItem1 = new TextItem ();
        textItem1.setTitle ("TextItem1");
        textItem1.setValue ("111");
        
        // create a TextItem with an initial value NOT set
        final FormItem textItem2 = new TextItem ();
        textItem2.setTitle ("TextItem2");
        
        // create a TextItem with an initial value set and cleared to fool the underlying library
        final FormItem textItem3 = new TextItem ();
        textItem3.setTitle ("TextItem3");
        textItem3.setValue ("test");
        textItem3.setValue ("");
    
        // load form
        final DynamicForm form = new DynamicForm ();
        form.setFields (
          textItem1,
          textItem2,
          textItem3);
    
        // Login button
        final IButton button = new IButton ();
        button.setAutoFit (true);
        button.setTitle ("Test");
        button.addClickHandler (new com.smartgwt.client.widgets.events.ClickHandler () {
          public void onClick (final com.smartgwt.client.widgets.events.ClickEvent event) {
            
            // log info about form elements
            GWT.log ("textItem1.getValue (): " + textItem1.getValue ());
            GWT.log ("textItem1.getDisplayValue (): " + textItem1.getDisplayValue ());
            GWT.log ("textItem1: " + textItem1);
            GWT.log ("");
            GWT.log ("textItem2.getValue (): " + textItem2.getValue ());
            GWT.log ("textItem2.getDisplayValue (): " + textItem2.getDisplayValue ());
            GWT.log ("textItem2: " + textItem2);
            GWT.log ("");
            GWT.log ("textItem3.getValue (): " + textItem3.getValue ());
            GWT.log ("textItem3.getDisplayValue (): " + textItem3.getDisplayValue ());
            GWT.log ("textItem3: " + textItem3);
          }
        });
    
        // display
        final VLayout layout = new VLayout ();
        layout.setWidth100 ();
        layout.setHeight100 ();
        layout.addMember (form);
        layout.addMember (button);
        layout.draw ();
      }
    }
    Posts with incomplete information are much more likely to be ignored:
    IE and Chrome look like this:
    11:05:43.773 [INFO] textItem1.getValue (): 111
    11:05:43.773 [INFO] textItem1.getDisplayValue (): 111
    11:05:43.773 [INFO] textItem1: com.smartgwt.client.widgets.form.fields.TextItem@15d94db
    11:05:43.773 [INFO] textItem2.getValue (): null
    11:05:43.773 [INFO] textItem2.getDisplayValue (): 222
    11:05:43.773 [INFO] textItem2: com.smartgwt.client.widgets.form.fields.TextItem@287e34
    11:15:50.570 [INFO] textItem3.getValue ():
    11:15:50.570 [INFO] textItem3.getValue (): 333
    11:15:50.570 [INFO] textItem3: com.smartgwt.client.widgets.form.fields.TextItem@157942f

    #2
    This regression was fixed a couple of days ago. Try using the latest nightly.

    Comment

    Working...
    X