You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Borja Martín <bo...@dagi3d.net> on 2005/04/08 16:59:35 UTC

own validator not called

hi,
I have seen that my own validator method isnt called when the field 
value is empty(I'm making this to be able to get some sent form values 
during the validation). I have this:

...
<h:inputText id="title" value="#{news.title}" 
validator="#{news.validateTitle}" />
<h:message for="title" />
...


and in the NewsForm class:
...
public void validateTitle(FacesContext context, UIComponent comp, Object 
obj)
{
    throw new ValidatorException(
            new FacesMessage("just testing the method is called"));
}


as you can see the method should send the a validatorexception whenever 
the form is sent(just for testing purposes). well, if the field is 
totally blank it isnt called, but when it contains at least one 
character it is.

Maybe that has something to do with what we talked before about that 
previously blank fields where handled as empty strings and now as null 
values...

thanks in advance



Re: own validator not called

Posted by Heath Borders <he...@gmail.com>.
No, the submittedValue is null, no validators will ever be fired.

On Apr 8, 2005 10:13 AM, Borja Martín <bo...@dagi3d.net> wrote: 
> 
> Heath Borders wrote:
> 
> > This is a known issue with the JSF spec. The spec says that for any
> > UIInput if the submittedValue is null, validation should not be
> > called. There's nothing that we can do about it if we want to remain
> > standards compliant.
> >
> then suppose I have a value that I should handle throughtout the whole
> application but cannot use sessions for this (for example a selected id
> of a newsitem in a editor)
> then if use the 'required' attribute I cannot retrieve it as the model
> updating phase comes after the validating one.
> But if I use my own validator I can get this variable and validate the
> field value as I want(including if was empty or not)
> 
> >
> > On Apr 8, 2005 9:59 AM, *Borja Martín* <borjam@dagi3d.net
> > <ma...@dagi3d.net>> wrote:
> >
> > hi,
> > I have seen that my own validator method isnt called when the field
> > value is empty(I'm making this to be able to get some sent form values
> > during the validation). I have this:
> >
> > ...
> > <h:inputText id="title" value="#{news.title}"
> > validator="#{news.validateTitle}" />
> > <h:message for="title" />
> > ...
> >
> > and in the NewsForm class:
> > ...
> > public void validateTitle(FacesContext context, UIComponent comp,
> > Object
> > obj)
> > {
> > throw new ValidatorException(
> > new FacesMessage("just testing the method is called"));
> > }
> >
> > as you can see the method should send the a validatorexception
> > whenever
> > the form is sent(just for testing purposes). well, if the field is
> > totally blank it isnt called, but when it contains at least one
> > character it is.
> >
> > Maybe that has something to do with what we talked before about that
> > previously blank fields where handled as empty strings and now as null
> > values...
> >
> > thanks in advance
> >
> >
> >
> >
> > --
> > -Heath Borders-Wing
> > hborders@mail.win.org <ma...@mail.win.org>
> 
> 


-- 
-Heath Borders-Wing
hborders@mail.win.org

Re: own validator not called

Posted by Borja Martín <bo...@dagi3d.net>.
Heath Borders wrote:

> This is a known issue with the JSF spec.  The spec says that for any 
> UIInput if the submittedValue is null, validation should not be 
> called.  There's nothing that we can do about it if we want to remain 
> standards compliant.
>
then suppose I have a value that I should handle throughtout the whole 
application but cannot use sessions for this (for example a selected id 
of a newsitem in a editor)
then if use the 'required' attribute I cannot retrieve it as the model 
updating phase comes after the validating one.
But if I use my own validator I can get this variable and validate the 
field value as I want(including if was empty or not)

>  
> On Apr 8, 2005 9:59 AM, *Borja Martín* <borjam@dagi3d.net 
> <ma...@dagi3d.net>> wrote:
>
>     hi,
>     I have seen that my own validator method isnt called when the field
>     value is empty(I'm making this to be able to get some sent form values
>     during the validation). I have this:
>
>     ...
>     <h:inputText id="title" value="#{news.title}"
>     validator="#{news.validateTitle}" />
>     <h:message for="title" />
>     ...
>
>     and in the NewsForm class:
>     ...
>     public void validateTitle(FacesContext context, UIComponent comp,
>     Object
>     obj)
>     {
>        throw new ValidatorException(
>                new FacesMessage("just testing the method is called"));
>     }
>
>     as you can see the method should send the a validatorexception
>     whenever
>     the form is sent(just for testing purposes). well, if the field is
>     totally blank it isnt called, but when it contains at least one
>     character it is.
>
>     Maybe that has something to do with what we talked before about that
>     previously blank fields where handled as empty strings and now as null
>     values...
>
>     thanks in advance
>
>
>
>
> -- 
> -Heath Borders-Wing
> hborders@mail.win.org <ma...@mail.win.org> 



Re: own validator not called

Posted by Heath Borders <he...@gmail.com>.
This is a known issue with the JSF spec. The spec says that for any UIInput 
if the submittedValue is null, validation should not be called. There's 
nothing that we can do about it if we want to remain standards compliant.

 On Apr 8, 2005 9:59 AM, Borja Martín <bo...@dagi3d.net> wrote: 
> 
> hi,
> I have seen that my own validator method isnt called when the field
> value is empty(I'm making this to be able to get some sent form values
> during the validation). I have this:
> 
> ...
> <h:inputText id="title" value="#{news.title}"
> validator="#{news.validateTitle}" />
> <h:message for="title" />
> ...
> 
> and in the NewsForm class:
> ...
> public void validateTitle(FacesContext context, UIComponent comp, Object
> obj)
> {
> throw new ValidatorException(
> new FacesMessage("just testing the method is called"));
> }
> 
> as you can see the method should send the a validatorexception whenever
> the form is sent(just for testing purposes). well, if the field is
> totally blank it isnt called, but when it contains at least one
> character it is.
> 
> Maybe that has something to do with what we talked before about that
> previously blank fields where handled as empty strings and now as null
> values...
> 
> thanks in advance
> 
> 


-- 
-Heath Borders-Wing
hborders@mail.win.org