• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts Validation not working

 
Mallika R Kumar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to get validation framework to work in my application. I have two jsp pages that use the validator framework with struts - while the first jsp page, login.jsp executes validations fine(checking required and minlength rules for login and password fields), the second page, myPage is not executing validations at all. Here are the relevant tags for myPage.jsp :
form-bean tags for "myForm" from struts-config.xml:
<form-bean name="myForm" type="org.apache.struts.validator.DynaValidatorActionForm">
<form-property name="name" type="java.lang.String"/>
<form-property name="desc" type="java.lang.String"/>
</form-bean>
The action mapping tags from struts-config.xml are:
<action path="/myPage"
type="struts.actions.MyPageAction"
name="myForm"
scope="request"
validate="true"
input="/myPage.jsp">
<forward name="failure" path="/errorpage.jsp"/>
<forward name="success" path="/menu.jsp"/>
</action>
Tags from my validation.xml are as follows:
<formset>
<form name="/myPage">
<field
property="name"
depends="required,minlength">
<arg0 key="mypage.label.name"/>
<arg1 name="minlength" key="5" resource="false"/>
</field>

<field
property="desc"
depends="required,minlength">
<arg0 key="mypage.label.desc"/>
<arg1 name="minlength" key="${var:minlength}" resource="false"/>
<var>
<var-name>minlength</var-name>
<var-value>5</var-value>
</var>
</field>
</form>
</formset>
I am using two formset tags, one for each jsp page. While the login.jsp page's validations work fine, I am unable to get "myPage.jsp" validations to work. I will appreciate any insight into this problem.
Thanks,
Mallika.
 
Rick Hightower
Author
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in your form in validation.xml change
<form name="/myPage">

to
<form name="myForm">
 
Rick Hightower
Author
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Professional Struts (a book) has very good step-by-step instructions how to use the Validator framework with really good descriptions.
 
Mallika R Kumar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rick,
I replaced "/myPage" with "myForm" in the validation.xml file's form name tag, but still I get the same result. The validations are just bypassed, and I can get to menu.jsp when I hit the submit button on myPage.jsp. I also tried making the Dynamic form bean a class of type org.apache.struts.validator.DynaValidatorForm instead of DynaValidatorActionForm, but did not see any difference in the outcome.
Am I missing something here ?
Thanks,
Mallika.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic