aspose file tools*
The moose likes Struts and the fly likes why different kind of validations in Struts.explain me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "why different kind of validations in Struts.explain me" Watch "why different kind of validations in Struts.explain me" New topic
Author

why different kind of validations in Struts.explain me

sreenivas jeenor
Ranch Hand

Joined: Jan 09, 2005
Posts: 125
Hi ranchers,

we have javascript validation for client side.
we have got validate method in ActionForm class.
and Validator framework.

why so different types for validation.explain me..

Thanks
anuradha chekuri
Greenhorn

Joined: Apr 20, 2006
Posts: 10
Hi Sreenivas, sorry that i am not giving you any answer.As i have doubt similar to you i am posting reply here.

Hi Ranchers,

Normally we have form class in struts application where we define error messages for validation.But for the one which are retrieved dynamically and do not have any form class,where we can define action errors.Can any one help me in this issue.I already defined fields in validation.xml file.But want to define action errors where can i do this.Or there is no way in struts to do it.Can any one help.

Thanks
Anu


annu
Meera Godse
Greenhorn

Joined: Jan 09, 2007
Posts: 28
"we have javascript validation for client side.
we have got validate method in ActionForm class.
and Validator framework. why so different types for validation."


Hi Shreenivas, I am new to validator framework myself, so this wont be the experts opinion but heres my explanation...
The validator helps us to automate the client &/or server side validations. In case of client-side validations, if you implement the validator, it will generate all the javascript for you instead of you having to code in javascript. This saves your time & effort and for any future changes, its easy to modify the config & xml files.

For server-side validation, one way is to write the code in the validate method of form-bean. But again, if you use the validator, the form-bean class must extend ValidatorForm class (or DynaValidatorForm and so on), which automatically creates the validate method for you. so you do not need to code for the validate method yourself.

So, you can use any of the option you like for your code. I hope this was helpful.
- Meera.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
sreenivas:

It is really not that complicated. There is the validator framework that supports both server-side and client-side validations. You define you validation rules in just one place (validation.xml). In this case your action forms should extend ValidatorForm. The implementation of the validate method in ValidatorForm calls the validator framework.

You can also choose to not use the validator framework and write your own validation code in the validate method of your form. This is really not that much work and it is a valid strategy. You can also use a combination of rules defined using the validator framework and your own validation in the validate method (be sure to call super.validate()).

anuradha: I don't really understand what you are asking?

- Brent
Meera Godse
Greenhorn

Joined: Jan 09, 2007
Posts: 28
"You can also use a combination of rules defined using the validator framework and your own validation in the validate method (be sure to call super.validate())."


How to do that ? I have already posted this as a separate thread but i am not getting any response on that. There are a few instances in my code where i must write my own javascript methods in addition to the ones supported by the validator. How & from where do I call these methods ? Onsubmit option is ruled out as the validator uses that. So how do I call my own methods which i want to be called say after the validator methods end ? pls help .
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I have never used client-side validation so I do not know the details. I took a glance at your other thread and the tip and link by Dom look good. No you cannot use the validate method on the form to implement client-side javascript validation. This method is only called on the server-side after your form has been submitted.

- Brent
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why different kind of validations in Struts.explain me