Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Struts 2 »

Validate length of array

O'Shea, Sean

2006-12-05

Replies:

Hi all,

I'm using struts 1.2.7 with commons-validator 1.1.4

I've this DynaValidatorActionForm which has the following properties:

<form-bean name="TOAForm" dynamic="true"
 type="org.apache.struts.validator.DynaValidatorActionForm">
 <form-property name="fundsTransfer" type="com.myform.Transfer[]"
size="3" />
 <form-property name="id" type="java.lang.String" />
</form-bean>

I have the corresponding rules defined:

<form name="/brokeragePartialTransfer">
 <field property="fundName" indexedListProperty ="fundsTransfer"
depends="required,minlength,maxlength">      
 <arg key="TOAForm.fundName" position="0"/>
 <arg1 name="minlength" key="${var:minlength}" resource="false"
position="1"/>
 <arg2 name="maxlength" key="${var:maxlength}" resource="false"
position="1"/>
   <var>
     <var-name>minlength</var-name>
     <var-value>3</var-value>
   </var>
   <var>
       <var-name>maxlength</var-name>
       <var-value>20</var-value>
   </var>
 </field>      
 <field property="noOfShares" indexedListProperty
="fundsTransfer" depends="required,minlength,maxlength">

 <arg key="TOAForm.noOfShares" />
 <arg name="minlength" key="${var:minlength}" resource="false"
position="1"/>
 <arg name="maxlength" key="${var:maxlength}" resource="false"
position="1"/>        
   <var>
       <var-name>minlength</var-name>
       <var-value>3</var-value>
   </var>
   <var>
       <var-name>maxlength</var-name>
       <var-value>20</var-value>
   </var>
 </field>
 ....
</form>

From my understanding, these validations will validate the noOfShares
and fundName properties which are part of the com.myform.Transfer POJO.
In addition to these individual validations I also need to ensure that
the user has entered at least one com.myform.Transfer bean. ie. I need
to make sure that the fundsTransfer array has a size of greater than 1.
Is there a way to include this type of validation in XML format?

Hope someone has come across this problem before and can offer some help

Thanks

Sean O Shea


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.