File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help to add validation

 
Nitin Parashar
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic