users@javaserverfaces.java.net

Re: JSF 1.1 null value not entering custom Validator

From: Raymond DeCampo <rdecampo_at_twcny.rr.com>
Date: Tue, 25 Nov 2008 21:39:10 -0500

Fhomasp wrote:
> Hey,
>
> I'm using JSF 1.1, not by choice.
>
> I've written a custom validator to validate a certain number sequence which
> is in predetermined format. It works but only if something is written in
> the field. The field is required so a null value chould also output a
> validation message.
>
> I know from JSF 1.2 it's possible to use requiredMessage = "<message>" but
> that's pretty much out of the question.
>
> Googling around I found an implementation to override the standard method:
> validate(FacesContext)
> It roughly goes like this:
>
> And now the Q..
> I'm unsure where I need to override/extend the configuration so that the
> standard <h:textField> uses this validate method instead of the standard
> that doesn't use a validator when the input value is null.
>
>
I think you are stuck -- JSF won't call the validator if the field is
null, using the required attribute is supported method. Obviously there
were shortcomings which were addressed in 1.2, but those do not help you
very much. If you wish to change the required message, you could define
an alternate bundle to use in place of javax.faces.Messages via the
<message-bundle> configuration in the faces-config.xml. Unfortunately
that changes the message for the entire application; the messages are
parametrized however, so there is a possibility to make it work.

Assuming that does not work for you, I think the alternative is
extending UIInput (or the appropriate subclass) and overriding the
proper method to make null values go through the validator.

Good luck,
Ray