• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use Validators

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I wrote my first program using validators.The validation is not kicking in.What should I do? My program is as follow.

struts-config.xml:

<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/org/apache/struts/validator/validator-rules.xml,
/WEB-INF/validation.xml"/>
</plug-in>

validation.xml :

<form name="UserRegistrationForm">
<field property="lastName" depends="required">
<arg key="UserRegistrationForm.lastName" />
</field>
</form>

UserRegistrationForm:
import org.apache.struts.validator.*;
public class UserRegistrationForm extends ValidatorForm{
private String firstName;
private String lastName;
// some getter and setters here

and I removed the validate method here in this form.
What else I should do to work the validation.what is that validation-rules.xml?I didn't see that in my directory structure. please explain.

Thanks,
sudha.
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The validator-rules file contains the default Struts Validator definitions. You need to place this file in your web app.
 
sudha javvadi
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you please explain how to place that validator-rules.xml file in my webapp.

Thanks,
sudha.
 
sudha javvadi
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I forgot to mention that I am using struts1.3.

Thanks,
sudha.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put the file in the same directory as the validation.xml file.
 
sudha javvadi
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi James,

I am using struts1.3.8 with tomcat 6 server. Under WEB-INF I have lib and src.Under src I have struts-config.xml,validation.xml and web.xml. I dont have validator-rules.xml.How do I get this file? Is this file builtin for struts 1.3.8? please explain.

Thanks,
sudha.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Apache Commons Validator can be used without Struts. I would download the most current version of the rules file from the following link and add it to your web app in the same directory as the validation.xml file.

http://commons.apache.org/validator/
 
sudha javvadi
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you! James.
 
reply
    Bookmark Topic Watch Topic
  • New Topic