Display custom conversion error message with <rich:beanValidator />
-
21-08-2019 - |
Question
I'm using hibernate validators with JSF. How can I set my conversion error messages? I am using them in the following way, but it didn't work:
<h:inputText id="input" value="#{myBean.number}" converterMessage="#{msgs.convertError}">
<f:convertNumber />
<rich:beanValidator />
<rich:ajaxValidator event="onblur"/>
</h:inputText>
I can set custom validator messages in my bean like this:
@NotNull
@Min(value = 1, message="{greateThanOne}")
public long getNumber() {
return number;
}
But what to do with conversion errors?
Solution
You may want to look into Faces resource file (jsf-api.jar, javax/faces/Messages.properties). Just define the following keys in your own resource file and configure it in faces-config.xml.
javax.faces.converter.NumberConverter.NUMBER={2}: ''{0}'' is not a number.
javax.faces.converter.NumberConverter.NUMBER_detail={2}: ''{0}'' is not a number. Example: {1}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow