webtier@glassfish.java.net

Re: [webtier] Custom validator, empty inputTextarea

From: <webtier_at_javadesktop.org>
Date: Sat, 23 Aug 2008 06:28:01 PDT

Hrm, I've just looked it up in the sources. It's not possible to create a custom Validator for required fields, since required is handled as a special case in UIInput. This prevents your custom required Validator to be called, since UIInput prevents this.

Just look at this code snippet from UIInput:
protected void validateValue(FacesContext context,Object convertedValue)
{
    boolean empty = convertedValue == null ||
        (convertedValue instanceof String
        && ((String)convertedValue).length() == 0);

    if (isRequired() && empty)
    {
        _MessageUtils.addErrorMessage(context, this, REQUIRED_MESSAGE_ID,new Object[]{getId()});
        setValid(false);
        return;
    }

    if (!empty)
    {
        _ComponentUtils.callValidators(context, this, convertedValue);
    }

}

This !empty check will prevent any Validator on your component to be called, causing it to always succeed, even when you haven't filled in anything.

So, I think you just have to use a bean validator method.
[Message sent by forum member 'jkva' (jkva)]

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