Article:
  Using the Validator Framework with Struts
Subject:   One form, multiple validations
Date:   2003-09-17 09:40:08
From:   anonymous2
I'm getting a bit confused with the XML validation system. I have one form (DynaValidatorForm), 3 JSPs followed by 3 actions that do nothing. My Form has 3 fields:

name, address and phone, all String

Now, I have 3 different JSPs, test1, test2 and test3.jsp, each of them followed by an Action like this:
test1.jsp --> Test1Action --> test2.jsp --> Test2Action --> test3.jsp --> Test3Action

All of the JSP have the same code. I want to validate: the first field after submitting the first page, the second field after submitting the second page and the 3rd field after submitting the third page. My JSPs look like this:


(...)
<html:hidden property="page" value="<MY_PROBLEM>" />
<TABLE border="0">
<TBODY>
<TR>
<TH>name</TH>
<TD><html:text property="name" /></TD>
</TR>
<TR>
<TH>address</TH>
<TD><html:text property="address" /></TD>
</TR>
<TR>
<TH>phone</TH>
<TD><html:text property="phone" /></TD>
</TR>
<TR>
<TD><html:submit property="submit" value="Submit" /></TD>
<TD><html:reset /></TD>
</TR>
</TBODY>
</TABLE>
(...)


My validation.xml looks like this:
(...)
<form name="testeForm">
<field property="name" depends="required" page="0">
<arg0 key="prompt.name" />
</field>
<field property="address" depends="required" page="1">
<arg0 key="prompt.address" />
</field>
<field property="phone" depends="required" page="2">
<arg0 key="prompt.phone" />
</field>
</form>
(...)

Which value should I write in my page property inside the JSPs?

if I put:
<html:hidden property="page" value="0" />
in my test1.jsp I get the error that Name is required. Great. But then I put
<html:hidden property="page" value="1" />
in my test2.jsp and when I submit I don't get any error. And I get the same when I submit the 3rd JSP.

Does anybody know how to use this page property correctly?

Thanks a lot

Rúben Carvalho