I have a form page that has an inputText field that accepts a date. We have a converter that converts the string from the textbox into a Date object (ie. “2011-03-01” to java.util.Date(“2011-03-01″”) )
If the string is not a date, like “123” then a validation error message will be displayed like “value (123) must be a date”.
Currently, in my .properties file, I see:
javax.faces.converter.DateTimeConverter.DATE=value
({0}) must be a date
I need to make this error message more clear by specifying exactly which field must be a date. (As there could be more than one date text fields on the form).
I would like to change it to something like:
javax.faces.converter.DateTimeConverter.DATE=The
field “{0}” with value ({1}) must be a
date
However, I am unsure how JSF automatically fills in the {0} and {1}. How do I specify my own variables inside the JSF Converter error message?
Note: I have added tried creating my own validator (not to be confused with converter) but it seems that the JSF framework does conversion before validation in its lifecycle.
Starting from JSF 1.2, use the
converterMessageattribute to replace the entire message, such as:Otherwise, JSF by default shows the
_detailmessage 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 forf:convertDateTimeis the following:The
{2}will be substituted with the client ID or thelabelattribute of the input field when present.Both the
DATEandDATE_detailmessage must be defined for theDATE_detailmessage to be used:See also: