Thursday, December 5, 2013

What is the best practice for coding addChangeHandler in Gwt?

in UiBinder

@UiField ListBox testListBox;  

in presenter, I have a method getData() that put data into the testListBox.

public void getData(){          getView().getTestListBox().clear();          getView().getTestListBox().addItem("itm 1");          getView().getTestListBox().addItem("itm 2");          getView().getTestListBox().addItem("itm 3");          getView().getTestListBox().addChangeHandler(new ChangeHandler(){                @Override              public void onChange(ChangeEvent event) {                  // TODO Auto-generated method stub                  int ind=getView().getTestListBox().getSelectedIndex();                  System.out.println(getView().getTestListBox().getValue(ind));              }            });  }  

Now, i also have a button to call getData(). If i click that button 1 time, then I select "itm 1" in thetestListBox everything is fine as it will print out:

itm 1  

However, if I click that button 2nd times, & select "itm 1" then it prints out twice "itm 1":

itm 1  itm 1  

If i click it 3rd time, it will print out triple "itm 1"....

But if i put the getView().getTestListBox().addChangeHandler outside getData() method before i add the item into the listbox (ie I do the addChangeHandler before there is actual item inside the listbox), then everything is fine as it print out only 1 time.

So What is the best practice for coding addChangeHandler in Gwt?

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate