Alexander Jesse and I have just finished a component that will allow you to use a required validator rather than the required attribute. Lucky you! :)
Basically, it's a standard validator, and a <requiredValidatorChecker/> component that you add to the bottom of your form. The component goes through the component tree at the apply-request-value and decode value phases and runs the requiredValidator validator on all EditValueHolders that contain one as appropriate. It works great with MyFaces, but I don't know how it'll work with other JSF implementations. MyFaces runs it after it runs all other validators (since it's the last element on the form) and that's not behavior that's guaranteed. I'll probably commit something to sourceforge.net.jsf-comp in an hour or so. And yes, future implementations of JSF should dump the required attribute and make it a standard validator. However, there's going to be issues to be issues with validators that can't handle null or empty values. -Mike On 8/12/05, Marc Fonteijn <[EMAIL PROTECTED]> wrote: > I'm looking for ways to assign a specific error message for required > fields. Setting the javax.faces.component.UIInput.REQUIRED isn't a > solution because I want a specific message for different fields. > > I thought of implementing an custom validator (method) and doing my own > "required" check instead of using the "required=true" tag. Unfortunately > this is stated in section 3.5.5 in the JSF Specification 1.1: > > "Unless otherwise specified, components with a null local value cause the > validation checking by this Validator to be skipped. If a component should > be required to have a non-null value, a component attribute with the name > required and the value true must be added to the component in order to > enforce this rule." > > My conclusion is that the only way to enable this behaviour whould be to > overwrite the validate method in UIInput in an custom component. You can > see what that leads to, you'd have to make a custom implementation of > every component that extends UIInput. > > Real solutions to this issue: > - Make the default validation behaviour of UIInput optional in order to be > able to write a custom validator that does the empty/null checking. > - Implement an additional attribute on UIInput "requiredMessage=....". > > Did I miss an alternative solution? > > Is this a flaw in the specification? > > > > Marc. > > -- > Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ >

