Meaningless Drivel is fun!*
The moose likes Struts and the fly likes difference between and validate() and validation.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "difference between and validate() and validation.xml" Watch "difference between and validate() and validation.xml" New topic
Author

difference between and validate() and validation.xml

Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
I want difference between and validate() and validation.xml and validator-rules.xml
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41089
    
  44
The Servlet API does not use files called validation.xml and validator-rules.xml; are you referring to some 3rd party library? And which class is supposed to have a "validate()" method?


Ping & DNS - my free Android networking tools app
Jasmine kaur
Ranch Hand

Joined: Nov 25, 2003
Posts: 157
The validate () method doesnt exist in servlet API rather these methods are from 3rd party like in struts where we can use the validate framaework and can the files which you have mentioned .

In validator-rules .xml we define the validation condition of the fields of our form and call then call
validate method to validate form in struts validator_rules.xml in our action class. We need to give path of all these configuration files in our web.xml file.

See some example of struts validator and runt that example and you will be able to understand well.


jasmine kaur
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Validate() is a method. There is no difference between the two XML files you mention other than name and what is conventionally contained within.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

(Slight expansion: validate() can be used to implement business-oriented logic that can't easily be put into XML configuration. The two XML files differ in that one generally contains the validators themselves, while the other contains the validations. That's an arbitrary distinction, since both files are listed in the Struts configuration.)
Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
still am not clear about this explanation. please
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What else do you want to know that wasn't provided here or in the Struts 1 documentation?
Alpesh Padra
Ranch Hand

Joined: Jan 10, 2010
Posts: 41
Validate() method is responsible for server side validation. Like validate user name / password with permission.
It's part of struts framework.


validation.xml & validation-rules.xml is responsible for client side validation like java script validation.
It's part of validation framework.
Validation framework is plugin for struts framework.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It also defines server-side validation.
Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
I mean validate() method in ActionForm . what situations validation.xml used and what situation validate()
method in ActionForm used
M Turner
Greenhorn

Joined: Dec 16, 2009
Posts: 25
Whether you put a given validation in an xml file or into the Java action depends on how complex the validation is. If you have validations that fit with in standard parameters that can be checked using the "bundled" validation types like "required,email,stringlength" then put those in your validation.xml file. If your validations are more complex then you can action's use the validation() method. In fact, you can use both together.

Rajni Patel
Ranch Hand

Joined: Sep 03, 2009
Posts: 84
I try to use validate() method and validation.xml both with the same action form with different field, but only validate() method populate but validation.xml rule is not populate. Please anybody could guide me?

for ex: I have
String name,
double salary

2 fields.

I validate name with validate() method and salary with validation.xml
so only from validate() method, name field validate but not salary.

So I am thinking validation.xml and validate() method both can not use for the same action form.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference between and validate() and validation.xml
 
Similar Threads
validation in struts
compare the date field with the current date in struts 2 validation.xml
Difference Between Validations
difference validation ,validator-rules
validator framework