set value of ComboBox using binders

Hello,

is there a way I can use a binder to set the value of a combobox, even if that value is not included in the combobox’s values?

Thanks

Hi,

have you tried to do it in the Binder’s ValueChangeListener?

-Olli

What do you mean?

In my case, the ComboBox has a list of values. But in some cases, the binder which tries to populate the ComboBox with a value which is not included in that list and throws an IllegalArgumentException.

Is there any way I can tell the ComboBox to display that “illegal” value with a validation message?

No, I don’t think so. You can probably hack it with JavaScript with something like

comboBox.getElement().executeJavaScript("$0.selectedItem='quux'");

but I don’t know if that’s a great idea.

the solution was way easier than expected:

  1. create a custom ComboBox component
  2. create a setValue() method which tries super.setValue() and catches the IllegalArgumentException and handles it
  3. use that custom ComboBox

the use of the custom ComboBox prevents the Binder from throwing the exception and stopping populating the fields =)

Sneaky!