Announcement

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

    Is there a better way to write this changehandler for a combox now?

    Hi, we're currently running smartgwt 6.0 from 2017. A common usecase for us is a combobox with lots of values, and we want the user to be able to dynamically type and match the row to select. The value we want out is an integer, the primary key to work with in the datasource.

    However, this made it complex to know when a unique row has been selected, since sometime it's selected with the mouse, and sometimes the user types until there is only one row 'left'.

    To know when we actually should perform an action when a unique row has been selected, i have a fairly complex handler method, see below. My questions are basically:

    1. is there a better way to do this in later versions? For example something like "distinctRowSelectedHandler" or something...

    2. Can you see any obvious thing i do that can be better?

    thoughts appreciated.

    Code:
        public void onChanged(ChangedEvent changedEvent) {
            Integer value = null;
            if(changedEvent.getValue()!=null){
                try {
                    if (changedEvent.getValue() instanceof Integer) {
                        value = (Integer) changedEvent.getValue();
                    }
                } catch (Exception e) {/*do nothing*/}
    
                if (value == null) {
                    return;
                }
            }
    //DO STUFF WITH THE ACTUALLY SELECTED ROW IF WE GET HERE
        }

    #2
    Have you seen selectedRecordChanged() and getSelectedRecord()?

    Comment


      #3
      I have. This code was written like forever ago, and if i remember it correctly, we couldn't get it to work when selecting via dynamic typing in the field. I'll give it another go then! (we're going through old code)

      Thanks for the quick response.

      Comment


        #4
        Would you happen to know when that method was added? I can't find it in 6.0.

        Comment


          #5
          It's a new 12.1 API.

          Comment


            #6
            Note that, while selectedRecordChanged() is indeed new to 12.1, getSelectedRecord() does exist in 6.0. So, if what you want is just to detect when a valid record/existing value has been selected, via whatever mechanism, versus a partial/invalid value being entered, then calling getSelectedRecord() from your changed handler should still produce the expected result, since the result of that method is already established (set or cleared) by the time changed() runs.
            Last edited by Isomorphic; 27th Nov 2019, 22:14.

            Comment

            Working...
            X