This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

difference between and validate() and validation.xml  RSS feed

 
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want difference between and validate() and validation.xml and validator-rules.xml
 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(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
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
still am not clear about this explanation. please
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What else do you want to know that wasn't provided here or in the Struts 1 documentation?
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It also defines server-side validation.
 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean validate() method in ActionForm . what situations validation.xml used and what situation validate()
method in ActionForm used
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!