How to use Validator to validate a form with an array of objects

C

Claire

I have Validator installed and working, I can validate the input on a
logon form correctly. However, logon form is a straight forward form
as in it simply has 3 strings (from struts-config.xml):

<form-bean name="logonForm"
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="username" type="java.lang.String"/>
<form-property name="password" type="java.lang.String"/>
<form-property name="type" type="java.lang.String"/>
</form-bean>

. . . but my problem is now when I have a form set up that contains
an array of objects, and trying to validate the input of one of the
properties of the object (from struts-config.xml):

<form-bean name="stockForm"
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="rows" type="app.Stock.StockRow[]"/>
<form-property name="action" type="java.lang.String"/>
</form-bean>

with StockRow consisting of (from StockRow.java):

private String code = "";
private String name = "";
private String depot = "";
private String depotId = "";
private String rrp = "";
private String price = "";
private String activeDate = "";
private String inactiveDate = "";
private String currentStock = "";
private String newStock = "";

So when I display the form in the jsp, I display many 'StockRow'
objects, each of the texts being indexed . . .

. . . so what I want to do is check that all of the 'newStock' fields
contain an integer, so I tried (from validation.xml):

<form name="stockForm">
<field property="newStock"
depends="integer">
<arg0 key="prompt.newStock"/>
</field>
</form>

along with changing:
property="rows.newStock"
property="app.Stock.StockRow.newStock"

but nothing is making the form validate that newStock contains an
integer value. Has anybody got any ideas as to what I need to do?

Many Thanks, Claire
 
S

Sudsy

Claire wrote:
<snip>

Claire, you'd help yourself immensely if you just used available
search engines. The javadocs and DTDs are similarly informative.
Now, you can either engage the services of a professional (I'm
available right now) or you can start digging, starting with the
indexedListProperty attribute of the field element in your
validation XML file...
Have fun! ;-)
 
R

Roedy Green

I have Validator installed and working,

That term is pretty broad. To make it clear I would add a few
adjectives to make clear which Validator you are talking about.

Hurray for package names!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top