Empty input value does not triggger @NotNull but it triggers @NotBlank

筅森魡賤 提交于 2019-12-06 05:29:56

Due to the nature of HTTP, empty request parameters are retrieved as empty string instead of null. So the @NotNull validator will never be triggered. It will only be triggered when the field is missing in the form or when it is disabled.

You can however configure JSF 2.x to interpret empty submitted values as null by adding the following context paramter to the 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 way the @NotNull will be triggered for empty fields.

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