Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display custom conversion error message with <rich:beanValidator />

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?


1 Answers

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}

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!