webtier@glassfish.java.net

UIInput validatorMessage bypasses formatting

From: <webtier_at_javadesktop.org>
Date: Tue, 06 Apr 2010 16:33:34 PDT

We all know we can globally override validator messages in resource bundles. For example, I can replace javax.faces.validator.LongRangeValidator.NOT_IN_RANGE for when <f:validateLongRange> finds a value not within a specified range. The javadoc is even handy for letting me know how I can format my message with placeholders for the min, max, and control's value.

For component-only overriding, things become disappointing. Any subclass of UIInput can use the validatorMessage attribute for this. With the right expression, we can even tap into resource bundles and internationalization. However, we cannot leverage formatting with placeholders. The code for UIInput#validateValue(..) never uses validatorMessage with javax.faces.component.MessageFactory to create a BindingFacesMessage for delayed java.text.MessageFormat processing.

Even if it did, what if your component had two or more validators, and depending on which validator failed, and just for that one component, you wanted a different validatorMessage? There are fancy tricks one can do with action listeners, component listeners, or phase listeners. However, you still can't get to the original parameters the validator wanted to send for formatting.

This forces your hand to discard all standard validators and write your own.
[Message sent by forum member 'toddiuszho']

http://forums.java.net/jive/thread.jspa?messageID=395603