Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multipage form validation

 
Alok Pota
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
validation.xml
==============

<form-validation>
<formset>
<form name="/EditWorkOrder">
<field property="dealerName" depends="required" page="1">
<arg0 key="Dealer name" resource="false" />
</field>
<field property="customField1" depends="required" page="2">
<arg0 key="Customer field 1" resource="false" />
</field>
</form>
</formset>
</form-validation>

The form is session scope. and my two JSP pages have the following.

page1.jsp
=========

<html:form action="/EditWorkOrder" >
<html:hidden property="page" value="1" />
...
</html:form>

page2.jsp
========

<html:form action="/EditWorkOrder" >
<html:hidden property="page" value="2" />
...
</html:form>

struts-form.xml (merged into the struts-config)
================================================

<form-bean
name="EditWorkOrderForm"
type="org.apache.struts.validator.DynaValidatorActionForm">
<form-property name="dealerName" type="java.lang.String" />
<form-property name="customField1" type="java.lang.String" />
</form-bean>


I still don't get any validation. I can jump from one page to another.

Am I missing something?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alok Pota:
<form-validation>
<formset>
<form name="/EditWorkOrder">
<field property="dealerName" depends="required" page="1">
<arg0 key="Dealer name" resource="false" />
</field>
<field property="customField1" depends="required" page="2">
<arg0 key="Customer field 1" resource="false" />
</field>
</form>
</formset>
</form-validation>


You need to refer to forms using their name (i.e. "EditWorkOrderForm"), not using the name of the Action the form submits to.
 
Dan Waters
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, he has defined his form to be a DynaValidatorActionForm and so the validation is tied to the action and not the form. He would have to
tie the rules to the form if it was defined as DynaValidatorForm

..
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dan Waters:
No, he has defined his form to be a DynaValidatorActionForm and so the validation is tied to the action and not the form. He would have to
tie the rules to the form if it was defined as DynaValidatorForm
..

Hmm. That was new to me. Thanks.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is very good ttutorial about Validate Framework of Struts.

http://www.javaranch.com/newsletter/Mar2003/newslettermar2003.jsp#struts
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic