JSF 2.0 - selectOneMenu defaults to 0 when empty

蓝咒 提交于 2019-12-03 20:33:54

This converter is unnecessary and makes no sense (I'd expect an UserConverter to convert between User and String, not between Long and String). Remove it.

Now, you need to tell JSF to interpret empty string submitted values as null. Add the following to your web.xml:

<context-param>
    <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
    <param-value>true</param-value>
</context-param>

This should solve the problem on most containers. But if you're using Tomcat or a fork/clone of it (JBoss AS, WebSphere AS, etc) and/or the container uses the Apache EL parser implementation, then you also need to add the following argument to its VM startup arguments:

-Dorg.apache.el.parser.COERCE_TO_ZERO=false

This will prevent the Apache EL parser from coercing the submitted value to the primitive's default, even though you're using a primitive wrapper type as property.

See also:


Unrelated to the concrete problem, you don't have a combobox there. That's just a simple dropdownlist. A combobox is an editable dropdownlist. Get your terms right ;)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!