Custom Variables in JSF Converter's Error Message

纵饮孤独 提交于 2019-12-03 11:23:48
BalusC

Starting from JSF 1.2, use the converterMessage attribute to replace the entire message, such as:

<h:inputText value="#{user.dateOfBirth}" converterMessage="Format must be: yyyy-MM-dd">
    <f:convertDateTime pattern="yyyy-MM-dd" />
</h:inputText>

Otherwise, JSF by default shows the _detail message in the <h:message>. Only when you use <h:message showDetail="false" showSummary="true"> then the one similar as in your question will be displayed. I'm not sure what JSF version you're using, but in my JSF 2.0.3 the default detail message for f:convertDateTime is the following:

javax.faces.converter.DateTimeConverter.DATE_detail = {2}: ''{0}'' could not be understood as a date. Example: {1}

The {2} will be substituted with the client ID or the label attribute of the input field when present.

<h:inputText value="#{user.dateOfBirth}" label="Date of birth">
    <f:convertDateTime pattern="yyyy-MM-dd" />
</h:inputText>

Both the DATE and DATE_detail message must be defined for the DATE_detail message to be used:

javax.faces.converter.DateTimeConverter.DATE=Date format must be: dd/mm/yyyy 
javax.faces.converter.DateTimeConverter.DATE_detail=Date format must be: dd/mm/yyyy

See also:

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