开发者

DropDownChoice - nothing selected, value -1?

I开发者_StackOverflow社区 have a DropDownChoice component on my Form and when the form is submitted and nothing is selected from the DropDownChoice, the default value that's returned is "-1". Is there are a way to change this behavior?


This behavior is controlled by a constant field

protected static final String NO_SELECTION_VALUE = "-1";

in AbstractSingleSelectChoice, which is a superclass of DropDownChoice.

You can't change this value in a subclass, so in order to change the value used, you would have to locate uses of this constant and override the methods that use it to use some other default.

Doing that would be risky, though it's likely possible. I know you'd have to override at least getDefaultChoice(final Object selected) and getModelValue().

Why do you wish to do this? It's a sensible value for its purpose.

Perhaps there's a better approach to accomplishing your underlying need.


Hook to the beforeSubmit, and change what you want. I think it is good to have such a value, Since first element is 0, notting means -1.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜