GeeCON Prague 2014*
The moose likes Struts and the fly likes Help to add validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Help to add validation " Watch "Help to add validation " New topic
Author

Help to add validation

Nitin Parashar
Ranch Hand

Joined: Jun 06, 2003
Posts: 52
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


SCJP 1.4, SCWCD 1.4, SCBCD 1.3
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
1) Made bookEditForm to extend BookEditForm instead of ActionForm


Now that you're using the Struts Validation Framework, BookEditForm should extend ValidatorForm.


Merrill
Consultant, Sima Solutions
Nitin Parashar
Ranch Hand

Joined: Jun 06, 2003
Posts: 52
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

Joined: Feb 15, 2005
Posts: 4864
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
 
subject: Help to add validation