Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts validation does not work

 
Jerry Wang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have defined my form

<form-bean name="registrationForm"
type="org.apache.struts.validator.DynaValidatorActionForm">
..
</form-bean>

And my action definition is

<action path="/register"
type="RegisterAction"
name="registrationForm"
validate="true"
scope="request">
</action>

I already configured the validator plugin in 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>

And in validation.xml

<form name="/register">
<field property="firstName"
depends="required">
<arg0 key="FirstName" resource="false"/>
</field>
</form>

It seems not working. Because I submit my form with the firstName blank I did not get the error messages as expected. I did put the

<html:errors/>

in my jsp page.

Please help and thanks in advance!
 
Nimchi Yung
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change your validation.xml to



--Nimchi
 
Jerry Wang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nimchi Yung:
Change your validation.xml to



--Nimchi


Thanks Nimchi,

I tried that in the first place and did not work. What other possible ways could make it not work?

Jerry
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nimchi is correct, though.

Another thing to check is that you are defining firstName in the formbean of struts-config.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic