3

I have a checkbox with a valueChangeHandler on it. It works when user check the checkbox.

For some reason, I need to set a value to this checkbox in my code, like this :

checkbox.setValue(true), the checkbox is perfectly checked visually but my problem is that it doesn't fire my valueChangeHandler.

checkBox.setValue(true);

checkBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
   @Override
   public void onValueChange(ValueChangeEvent<Boolean> event) {
     ...
   }
});

Is there another handler that can be fire when I set a value ? Or another way to dot this?

Thanks

EDIT : I also tried checkbox.setValue(true,true) but it doesn't work.

RESOLVED : the setValue MUST BE after the registration of the handler. Thanks

Hubertsa
  • 33
  • 1
  • 5

1 Answers1

6

That's the difference between setValue(Boolean) vs. setValue(Boolean,boolean)

checkBox.setValue(true, true);
Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • nope, checkBox.setValue(true,true) doesn't work neither – Hubertsa Sep 04 '14 at 09:48
  • That would mean that the checkbox value is already `true`. Or could it be a race condition between adding the event handler and calling `setValue`? Is the code really like you put it in the question (two lines next to each others)? Where is this code called from? In response to which event? – Thomas Broyer Sep 04 '14 at 12:36
  • It finally works. But the checkBox.setValue(true, true) must absolutely be after the checkBox.addValueChangeHandler. Otherwise it doesn't work. Thanks – Hubertsa Jul 09 '15 at 05:58