jsf - Customize converter message to include input with bolded invalid characters -
mojarra 2.1.29
consider standard javax.faces.integer
converter. if enter invalid number we'll recieve message:
'foo' must number consisting of 1 or more digits
i need customize message follows if number contains invalid charaters, print input along bolded invalid charaters. instance 1234add
the number contains invalid charaters: 1234add
i think it's not possible define own custom properties file containing message follows:
javax.faces.converter.bigintegerconverter.biginteger={2}: ''{0}'' must number consisting of 1 or more digits.
do have write own custom converter subclass of javax.faces.integer
?
is possible customize error-message in such way without writing custom converter?
yes, it's possible. it's hacky 2 reasons:
- formatting logic been encapsulated in el instead of in reusable java class (although create special tagfile prevent copypasting on place in case intend reuse same logic elsewhere).
- html needed in faces message while
<h:message>
doesn't support unescaping html (so<h:outputtext>
manually grabs message needed display message).
here 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 importance of binding
pointing local variable rather bean property.
Comments
Post a Comment