You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Narayana S <na...@gmail.com> on 2008/06/30 09:33:07 UTC

Validation doubt

Hi,

    as per my understanding, we can implement validations in struts 2 in the
following ways...

1. overriding validate() method in Action class
2. writing ActionClass-validation.xml file
3. using validator annotations

validate method implements declarative security, ActionClass-valication.xml
is  seperating validation logic  from  action class .

what is the  clear difference between these 3 approaches?

and how can i implement client side validations in struts 2?

Re: Validation doubt

Posted by Lukasz Lenart <lu...@googlemail.com>.
Hi,

> what is the  clear difference between these 3 approaches?

Annotations and XML allow you to only use defined validators, with
validate() method you can do anything you want, base your validation
on more complicated business rules.


> and how can i implement client side validations in struts 2?

Client side validation will base on validation rules defined with
Annotations and XML files, just add validate="true" to your form [1]

[1] http://struts.apache.org/2.1.2/docs/client-side-validation.html


Regards
-- 
Lukasz
http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Validation doubt

Posted by Narayana S <na...@gmail.com>.
Hi Jeromy and Lukasz,

             Thanks for your reply, the information provided by you is
really helpful. i could understand well about validation framework with your
explanation.

Thanks a lot.

On Mon, Jun 30, 2008 at 1:45 PM, Jeromy Evans <
jeromy.evans@blueskyminds.com.au> wrote:

> Narayana S wrote:
>
>> Hi,
>>
>>    as per my understanding, we can implement validations in struts 2 in
>> the
>> following ways...
>>
>> 1. overriding validate() method in Action class
>>
>>
>
> Use the validate() method for complex validation that cannot be implement
> anywhere else. You want to avoid duplicating validation code so this method
> should be for special cases.
>
>  2. writing ActionClass-validation.xml file
>>
>>
>
> The XML validation was developed first before Java 5 annotations can be
> assumed.  It is a little more mature than annotations but some people
> doesn't like having to manage more configuration files.
>
>
>  3. using validator annotations
>>
>>
>>
> The annotations implement much of what is available in XML and avoid the
> separate configuration.  There are some complications when using annotations
> but generally they're fine.  Sometimes I've found the validation annotations
> are longer than the actual code, which is a bad thing.  I prefer XML, many
> people prefer annotations.
>
>
>  and how can i implement client side validations in struts 2?
>>
>>
>
> The struts 2 form tags have client-side validation built-in if you set
> validate=true on the form.
> What actually happens is that a loop in the form's closing-tag template
> reads the validations from the xml/annotations of your action and generates
> some javascript implementing whatever validation logic it can from the
> client-side.  The benefit is that one validation declaration can be used for
> both client and server-side.  However it can't implement all validation
> logic, it assumes you're using struts2 tags and markup for all fields and it
> generates inline javascript.
>
> See:
> http://struts.apache.org/2.0.11.1/docs/client-side-validation.html
>
> regards,
> Jeromy Evans
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Validation doubt

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Narayana S wrote:
> Hi,
>
>     as per my understanding, we can implement validations in struts 2 in the
> following ways...
>
> 1. overriding validate() method in Action class
>   

Use the validate() method for complex validation that cannot be 
implement anywhere else. You want to avoid duplicating validation code 
so this method should be for special cases.

> 2. writing ActionClass-validation.xml file
>   

The XML validation was developed first before Java 5 annotations can be 
assumed.  It is a little more mature than annotations but some people 
doesn't like having to manage more configuration files.


> 3. using validator annotations
>
>   
The annotations implement much of what is available in XML and avoid the 
separate configuration.  There are some complications when using 
annotations but generally they're fine.  Sometimes I've found the 
validation annotations are longer than the actual code, which is a bad 
thing.  I prefer XML, many people prefer annotations.


> and how can i implement client side validations in struts 2?
>   

The struts 2 form tags have client-side validation built-in if you set 
validate=true on the form.
What actually happens is that a loop in the form's closing-tag template 
reads the validations from the xml/annotations of your action and 
generates some javascript implementing whatever validation logic it can 
from the client-side.  The benefit is that one validation declaration 
can be used for both client and server-side.  However it can't implement 
all validation logic, it assumes you're using struts2 tags and markup 
for all fields and it generates inline javascript.

See:
http://struts.apache.org/2.0.11.1/docs/client-side-validation.html

regards,
 Jeromy Evans


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org