You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by array <Ig...@img.de> on 2006/07/19 15:16:08 UTC

validation method problem

I have an input field on my form and I would like to validate the entered
value. I have defined a validator in the JSF configuration file and bound it
to the field with a ?validator? attribute. If I fill in some value in the
field and execute the action, the myfaces container invokes my validation
method. But if I put no value in the field the action method is performed
without invoking the validation method. Is it a bag or a normal behavior of
JSF container?

Thanks in advance

Igor
-- 
View this message in context: http://www.nabble.com/validation-method-problem-tf1966234.html#a5395996
Sent from the MyFaces - Users forum at Nabble.com.


Re: validation method problem

Posted by Cosma Colanicchia <co...@gmail.com>.
Usually the type of thing you're trying to do is done this way:

1) Assign an id attribute to each of your input field
2) Place an <h:messages forId="yourComponentId"> instead of your DIV

Now, any conversion/validation error will be rendered near the correct
field. Remember also to use an <h:messages globalOnly="true">
somewhere on your page to display errors that are not bound to any
particular fields. Again, using the Trinidad input components you
don't have to explicitly put an <h:messages> for it, it is done
automatically (unless you disable it with the "simple" attribute).

About the "required" attribute, I've found the JSF behaviour useful
for my apps, but I can understand that is a bit "enforced".

Cosma

2006/7/20, Mike Kienenberger <mk...@gmail.com>:
> The ability to customize the required message was provided for JSF 1.2.
>
> https://javaserverfaces-spec-public.dev.java.net/issues/show_bug.cgi?id=81
>
> There's no easy way to do it in JSF 1.1.
>
> It can be done if you want to spend processing time on it.
>
> The last section of this page will show you how.
>
> http://wiki.apache.org/myfaces/OptionalValidationFramework
>
> You'll want to write your own required-validator (or modify the existing one).
>
>
> On 7/20/06, array <Ig...@img.de> wrote:
> >
> > hi,
> >
> > What I would like to do during the validation is to add a div where the
> > error message has to be rendered. I have several divs on the page under each
> > input field which at first are not visible. The corresponding ?rendered?
> > attributes should to be set to true only if the validation fails.
> >
> > I don?t understand only one thing: why is the custom validator not invoked
> > if the ?required? validator reports an error. I could in my validator check
> > on null and do what I want!!!
> >
> > Trinidad components that allows a "label" attribute for input components
> > that can easily be internationalized is a nice thing!
> >
> > Igor
> >
> > --
> > View this message in context: http://www.nabble.com/validation-method-problem-tf1966234.html#a5415753
> > Sent from the MyFaces - Users forum at Nabble.com.
> >
> >
>

Re: validation method problem

Posted by Mike Kienenberger <mk...@gmail.com>.
The ability to customize the required message was provided for JSF 1.2.

https://javaserverfaces-spec-public.dev.java.net/issues/show_bug.cgi?id=81

There's no easy way to do it in JSF 1.1.

It can be done if you want to spend processing time on it.

The last section of this page will show you how.

http://wiki.apache.org/myfaces/OptionalValidationFramework

You'll want to write your own required-validator (or modify the existing one).


On 7/20/06, array <Ig...@img.de> wrote:
>
> hi,
>
> What I would like to do during the validation is to add a div where the
> error message has to be rendered. I have several divs on the page under each
> input field which at first are not visible. The corresponding ?rendered?
> attributes should to be set to true only if the validation fails.
>
> I don?t understand only one thing: why is the custom validator not invoked
> if the ?required? validator reports an error. I could in my validator check
> on null and do what I want!!!
>
> Trinidad components that allows a "label" attribute for input components
> that can easily be internationalized is a nice thing!
>
> Igor
>
> --
> View this message in context: http://www.nabble.com/validation-method-problem-tf1966234.html#a5415753
> Sent from the MyFaces - Users forum at Nabble.com.
>
>

Re: validation method problem

Posted by array <Ig...@img.de>.
hi,

What I would like to do during the validation is to add a div where the
error message has to be rendered. I have several divs on the page under each
input field which at first are not visible. The corresponding ?rendered?
attributes should to be set to true only if the validation fails.

I don?t understand only one thing: why is the custom validator not invoked
if the ?required? validator reports an error. I could in my validator check
on null and do what I want!!!

Trinidad components that allows a "label" attribute for input components
that can easily be internationalized is a nice thing!

Igor

-- 
View this message in context: http://www.nabble.com/validation-method-problem-tf1966234.html#a5415753
Sent from the MyFaces - Users forum at Nabble.com.


Re: validation method problem

Posted by Cosma Colanicchia <co...@gmail.com>.
2006/7/19, array <Ig...@img.de>:
>
> thanks for quick answer!
>
> I would like to perform some operations during the validation. Furthermore I
> would like to render an internalized error message. However the built-in
> ?required? validator uses the field id in his error message. How can I
> achieve these two requirements if I can?t invoke my logic without a value
> filled in? You mean there is a way to plug-in a custom required logic? Could
> you tell me how can I do this?
>
> Igor
> --
> View this message in context: http://www.nabble.com/validation-method-problem-tf1966234.html#a5397021
> Sent from the MyFaces - Users forum at Nabble.com.
>
>

1) About "perform some operations during the validation", what do you
mean exactly? It looks to me that you're trying, in your validator, to
do more than what should be done there. Maybe you could explain better
what you want to obtain.

2) Standard error messages, such as the one returned for missing
required fields, are already internationalizated in JSF. Maybe you are
referring to the "field name" that appears in the error message.. I
don't know how this can be done with standard JSF/MyFaces, I'm using
Trinidad components that allows a "label" attribute for input
components that can easily be internationalized.

Cosma

Re: validation method problem

Posted by Romain PELISSE <ro...@atosorigin.com>.
You can easily replace the default message by adding the following file 
to your webapp :

/javax/faces/Messages_XX.properties

then overload the message which to change :

# standard messages (Spec. 2.5.1.4)

javax.faces.component.UIInput.REQUIRED = validation Error
javax.faces.component.UIInput.REQUIRED_detail = MY MESSAGE !!!


array wrote:
> thanks for quick answer!
>
> I would like to perform some operations during the validation. Furthermore I
> would like to render an internalized error message. However the built-in
> ?required? validator uses the field id in his error message. How can I
> achieve these two requirements if I can?t invoke my logic without a value
> filled in? You mean there is a way to plug-in a custom required logic? Could
> you tell me how can I do this?
>
> Igor
>   


Re: validation method problem

Posted by array <Ig...@img.de>.
thanks for quick answer!

I would like to perform some operations during the validation. Furthermore I
would like to render an internalized error message. However the built-in
?required? validator uses the field id in his error message. How can I
achieve these two requirements if I can?t invoke my logic without a value
filled in? You mean there is a way to plug-in a custom required logic? Could
you tell me how can I do this?

Igor
-- 
View this message in context: http://www.nabble.com/validation-method-problem-tf1966234.html#a5397021
Sent from the MyFaces - Users forum at Nabble.com.


Re: validation method problem

Posted by Cosma Colanicchia <co...@gmail.com>.
I think this is the normal behaviour. "Required" validation is handled
in a special way in JSF.. if the field has to be required, you should
use the "required" attribute, and AFAIK there's now way to plug-in a
custom "required" logic.

Cosma


2006/7/19, array <Ig...@img.de>:
>
> I have an input field on my form and I would like to validate the entered
> value. I have defined a validator in the JSF configuration file and bound it
> to the field with a ?validator? attribute. If I fill in some value in the
> field and execute the action, the myfaces container invokes my validation
> method. But if I put no value in the field the action method is performed
> without invoking the validation method. Is it a bag or a normal behavior of
> JSF container?
>
> Thanks in advance
>
> Igor
> --
> View this message in context: http://www.nabble.com/validation-method-problem-tf1966234.html#a5395996
> Sent from the MyFaces - Users forum at Nabble.com.
>
>

Re: validation method problem

Posted by Gilles DEMARTY <gi...@gmail.com>.
another dirty solution is to write a custom UIInput component, and
override on this method the processValidate() (more exactly the
'validate()' ) to allow validation on the 'null value'
(remove the 'if (submittedValue == null) return;')




2006/7/19, Kapil Kataria <ka...@gmail.com>:
> Hi
>
> I need to create an application Using My Faces (JSF) and spring
>
> I am haven;t created any base framework using these technologies.
>
> If any one have some application working on these technologies.Please mail
> me Framework documentation >it will help me to design a new framework.
>
> Please mail me (katariakapil@gmail.com) documentation for any application
> working with JSF and spring.
>
>  Thanks In Advance
>

Re: validation method problem

Posted by Kapil Kataria <ka...@gmail.com>.
Hi

I need to create an application Using My Faces (JSF) and spring

I am haven;t created any base framework using these technologies.

If any one have some application working on these technologies.Please mail
me Framework documentation >it will help me to design a new framework.

Please mail me (katariakapil@gmail.com) documentation for any application
working with JSF and spring.

 Thanks In Advance

Re: validation method problem

Posted by Gilles DEMARTY <gi...@gmail.com>.
perfectly normal behavior.

The validators are triggered if a non-null value is provided.
If this you want to not allow null value,  add a required="true" on
your input component. (then null will then raise an error, but not
call your validator)/

2006/7/19, array <Ig...@img.de>:
>
> I have an input field on my form and I would like to validate the entered
> value. I have defined a validator in the JSF configuration file and bound it
> to the field with a ?validator? attribute. If I fill in some value in the
> field and execute the action, the myfaces container invokes my validation
> method. But if I put no value in the field the action method is performed
> without invoking the validation method. Is it a bag or a normal behavior of
> JSF container?
>
> Thanks in advance
>
> Igor
> --
> View this message in context: http://www.nabble.com/validation-method-problem-tf1966234.html#a5395996
> Sent from the MyFaces - Users forum at Nabble.com.
>
>