Mojarra 2.1.29
Consider the standard javax.faces.Integer
converter. If we enter an invalid number we'll recieve the message:
'foo' must be a number consisting of one or more digits
I need to customize the message as follows if the number contains invalid charaters, print the input along with bolded invalid charaters. For instance 1234add
The number contains invalid charaters: 1234add
I think it's not possible to just define my own custom properties file containing the message as follows:
javax.faces.converter.BigIntegerConverter.BIGINTEGER={2}: ''{0}'' must be a number consisting of one or more digits.
Do I have to write my own custom converter that is a subclass of the javax.faces.Integer
?
Is it possible to customize the error-message in such a way without writing a custom converter?
Yes, it's possible. It's only hacky for two reasons:
<h:message>
doesn't support unescaping HTML (so a <h:outputText>
which manually grabs the message is needed to display the message).Here it is:
<h:inputText binding="#{input}"
converter="javax.faces.Integer"
converterMessage="The number contains invalid charaters: #{input.submittedValue.replaceAll('(\\d*)?(\\D+)(\\d*)?', '$1<b>$2</b>$3')}" />
<h:outputText id="messageForInput" value="#{facesContext.getMessageList(input.clientId)[0].summary}" escape="false" />
Note the importance of binding
pointing to a local variable rather than a bean property.