DropDownChoice - nothing selected, value -1?

I have a DropDownChoice component in my form, and when the form is submitted and nothing is selected from DropDownChoice, the default return value is "-1". Is there any way to change this behavior?

+3
source share
2 answers

This behavior is controlled by a constant field.

protected static final String NO_SELECTION_VALUE = "-1";

in AbstractSingleSelectChoice, which is a superclass DropDownChoice.

You cannot change this value in a subclass, so to change the value you use, you will need to find the use of this constant and override the methods that use it to use some other default values.

, , , . , getDefaultChoice(final Object selected) getModelValue().

? .

, .

+2

beforeSubmit , . , . 0, notting -1.

+1

Source: https://habr.com/ru/post/1771468/


All Articles