struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton" <niall.pember...@gmail.com>
Subject Re: Validating list backed struts form
Date Fri, 09 Feb 2007 15:44:56 GMT
On 2/9/07, Chaudhary, Harsh <HCHAUDHA@amfam.com> wrote:
> Just tried it out and it does not work.
>
> My code look like this:
>
> I am using indexted='true' in my JSP file so an element looks like:
>
> <html:text name="element" property="addressLine1" size="20" value=""
> maxlength="35" indexed="true"/>
>
> The rendered JSP looks like:
>
> <input type="text" name="element[0].addressLine1" maxlength="35"
> size="20" value="Addr one">

Usually you would use this within a <logic:iterate> tag - something
like the following where you have a getAddressList() property that
returns your list:

  <logic:iterate id="addressList" name="form" property="addressList">
      <html:text name="addressList" property="addressLine1"/>
  </logic:iterate>

By using an "id" on the iterate tag thats the same as your list
property name it then generates the following kind of thing...

  <input type="text" name="addressList[0].addressLine1" ...>
  <input type="text" name="addressList[2].addressLine1" ...>

> My validation XML looks like:
>
>           <form name="AddressForm">
>                         <field property="addressLine1"
> indexedListProperty="element" depends="required">
>                                 <msg name="required"
> key="label.error.address.required"/>
>                         </field>
>           </form>

  <form name="AddressForm">
      <field property="addressLine1"
           indexedListProperty="addressList" depends="required">
  </form>

Niall

> Also, keeping in mind that I have 10 address fields which are required
> only if the fields are visible (it is a show hide kind of thing using
> JavaScript), is this even a good way to go in my case.
>
> Or should I just go ahead and build a custom validator.
>
> Harsh.
>
> -----Original Message-----
> From: Niall Pemberton [mailto:niall.pemberton@gmail.com]
> Sent: Friday, February 09, 2007 4:35 AM
> To: Struts Users Mailing List
> Subject: Re: Validating list backed struts form
>
>
> Specify the property in your form which returns the list of addresses
> using the "indexedListProperty" element in your validation.xml -
> "property" is then the property of a bean in that list. Something
> like:
>
> <form name="Customer">
>
>     <field property="city" indexedListProperty="addressList"
> depends="required">
>         ...
>     </field>
>
>     <field property="state" indexedListProperty="addressList"
> depends="required">
>         ...
>     </field>
>
> </form>
>
> Niall
>
> On 2/8/07, Chaudhary, Harsh <HCHAUDHA@amfam.com> wrote:
> > Hi,
> >
> > I am trying to validate a form which has an arraylist of Address
> > objects. I would like some pointers on this or any references etc.
> >
> > Harsh.
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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


Mime
View raw message