Announcement

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

    ChangedHandler not called on SelectItem when value changed programatically

    I have a SelectItem whose picklist is bound to a DataSource. I create the item and then its value programatically. All seems to work except that when I set the value programatically the ChangedHandler on the SelectItem *is not* called. However, the ChangedHandler on the SelectItem *is* called when I change the value manually using the items picklist.

    Here is my code:

    Code:
            final SelectItem selectItem = new SelectItem();
            selectItem.setTitle("Selection");
            selectItem.setDisplayField("Name");
            selectItem.setValueField("id");
    
            DataSource dataSource = ...
            String url = ...
            dataSource.setDataURL(url);
            selectItem.setOptionDataSource(dataSource);
    
            selectItem.addChangedHandler(new ChangedHandler() {
                public void onChanged(ChangedEvent event) {
                    SC.say("In ChangedHandler");
                }
            });
    
            selectItem.setValue("id1");
            selectItem.setValue("id2");
    I would have expected either both or second of the 2 calls to selectItem.setValue(...) to call the ChangedHandler but neither did that.

    What am I missing here? Thanks.

    #2
    events are only created with user interaction.
    Why do you need it to be called on setValue?

    Comment


      #3
      I call SelectItem.setValue since I need to set the initial value of the SelectItem to a value that is not the first pick in picklist. My UI needs to show a detail form when the selected value is changed in the SelectItem. This is not happening when I call setValue.

      It is fairly common in my experience that there are programmatic alternatives to UI interactions and in both cases needs to be identical. Are you sure this is not possible with SmartGWT? Many thanks.

      Comment


        #4
        By design. Firing change() on programmatic changes would fire change in a bazillion unexpected situations and lead to many possible infinite loops.

        If you need some logic to happen on user change and on selected programmatic changes, it's very easy to factor your code that way.

        Comment


          #5
          Dang you are good with your memory! Sorry that I forgot that design pattern in smartclient.

          Comment


            #6
            Originally posted by farrukh_najmi
            Dang you are good with your memory! Sorry that I forgot that design pattern in smartclient.
            could you tell us what pattern you are refering to?
            Thanks

            Comment


              #7
              Is there any way to fire change event programatically?

              Comment


                #8
                No. If you want a programmatic change to go to the same logic that you have added to a change() event, simply call the same logic from both places.

                Comment

                Working...
                X