You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "O'Shea, Sean" <Se...@fmr.com> on 2006/12/05 19:02:34 UTC

Validate length of array

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@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Validate length of array

Posted by Niall Pemberton <ni...@gmail.com>.
On 12/5/06, O'Shea, Sean <Se...@fmr.com> wrote:
> 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?

What you have looks OK - best way is to try it and see. There isn't a
"minimum indexed/array size validator shipped with any version of
Struts at the moment. You could write a custom one and "configure" it
through the validator's XML. If you do then the best way is to look at
the struts FieldChecks class to see how validators have been
implemented there.

Niall


> Hope someone has come across this problem before and can offer some help
>
> Thanks
>
> Sean O Shea

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org