• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Help to add validation

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

I am new to struts and need your help in adding a validation to one of my forms. Form name is bookEditForm and it has a value object book. I am trying to add validation for author field in book.

Everything works fine without validations, but I have started getting page not found error after I added the validation.

Changes made:

1) Made bookEditForm to extend BookEditForm instead of ActionForm

2)Added following entry to struts-config.xml

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

3) Included validator-rules.xml and following validation.xml in my war.


<form-validation>
<formset>
<form name="bookEditForm">
<field property="author" depends="required,minlength,maxlength">
<arg0 key="bookEditForm.book.author"/>
<arg1 key="${var:maxlength}" name="maxlength" resource="false"/>
<arg1 key="${var:minlength}" name="minlength" resource="false"/>
<var>
<var-name>minlength</var-name>
<var-value>5</var-value>
</var>
<var>
<var-name>maxlength</var-name>
<var-value>11</var-value>
</var>
</field>
</form>
</formset>
</form-validation>

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

1) Made bookEditForm to extend BookEditForm instead of ActionForm



Now that you're using the Struts Validation Framework, BookEditForm should extend ValidatorForm.
 
Nitin Parashar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry that was a typo error, I have made bookEditForm to extend ValidatorActionForm.

What is the difference between ValidatorActionForm and ValidatorForm?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You extend ValidatorActionForm if you specify an action mapping as the name in your validation.xml file. You extend ValidatorForm if you specify an ActionForm as the name in your validation.xml file. Since bookEditForm appears to be the name of an ActionForm, you should be extending ValidatorForm instead of ValidatorActionForm.
 
She still doesn't approve of my superhero lifestyle. Or this shameless plug:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic