You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Chaudhary, Harsh" <HC...@amfam.com> on 2007/02/08 19:36:08 UTC

Validating list backed struts form

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.

Re: Validating list backed struts form

Posted by Niall Pemberton <ni...@gmail.com>.
On 2/9/07, Chaudhary, Harsh <HC...@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 <HC...@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


RE: Validating list backed struts form

Posted by "Chaudhary, Harsh" <HC...@amfam.com>.
Hmmm.....cool. I will check it out.

Harsh.

-----Original Message-----
From: Niall Pemberton [mailto:niall.pemberton@gmail.com] 
Sent: Friday, February 09, 2007 10:05 AM
To: Struts Users Mailing List
Subject: Re: Validating list backed struts form


On 2/9/07, Chaudhary, Harsh <HC...@amfam.com> wrote:
> Thanks for all the tips Niall. Its working to the point that is
possible
> using Struts. Unfortunately, that does not solve my problem. And I
> cannot use your extension as we have this thing about registered jars
> here at work.

I understand - although it is ASF licensed so you could just grab the
source code into your project and do with it whatever you want.

Niall

> I guess a custom validator it is then.
>
> Harsh.
>
> -----Original Message-----
> From: Niall Pemberton [mailto:niall.pemberton@gmail.com]
> Sent: Friday, February 09, 2007 9:46 AM
> To: Struts Users Mailing List
> Subject: Re: Validating list backed struts form
>
>
> On 2/9/07, Chaudhary, Harsh <HC...@amfam.com> wrote:
> > Thanks for the tip. I will try this out now. Another question
though,
> is
> > it also possible to attach error messages for each  property
depending
> > on which property it is. An example would be:
> >
> > <form name="Customer">
> >
> >     <field property="city" indexedListProperty="addressList"
> > depends="required">
> >         <arg0 key="orderform.quantity.label[somethingHere]"/>
> >     </field>
> >
> > </form>
> >
> > Basically I want to have the error messages say, City 1 is required
or
> > City is required etc.
>
> Theres nothing in Struts to do this - but I have an extension that
> can, availbale here:
>
>
http://www.niallp.pwp.blueyonder.co.uk/strutsvalidatorextends.html#index
> ed
>
> Niall
>
> > I hope I was clear enough in my example.
> >
> > 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 <HC...@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
>
> ---------------------------------------------------------------------
> 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


Re: Validating list backed struts form

Posted by Niall Pemberton <ni...@gmail.com>.
On 2/9/07, Chaudhary, Harsh <HC...@amfam.com> wrote:
> Thanks for all the tips Niall. Its working to the point that is possible
> using Struts. Unfortunately, that does not solve my problem. And I
> cannot use your extension as we have this thing about registered jars
> here at work.

I understand - although it is ASF licensed so you could just grab the
source code into your project and do with it whatever you want.

Niall

> I guess a custom validator it is then.
>
> Harsh.
>
> -----Original Message-----
> From: Niall Pemberton [mailto:niall.pemberton@gmail.com]
> Sent: Friday, February 09, 2007 9:46 AM
> To: Struts Users Mailing List
> Subject: Re: Validating list backed struts form
>
>
> On 2/9/07, Chaudhary, Harsh <HC...@amfam.com> wrote:
> > Thanks for the tip. I will try this out now. Another question though,
> is
> > it also possible to attach error messages for each  property depending
> > on which property it is. An example would be:
> >
> > <form name="Customer">
> >
> >     <field property="city" indexedListProperty="addressList"
> > depends="required">
> >         <arg0 key="orderform.quantity.label[somethingHere]"/>
> >     </field>
> >
> > </form>
> >
> > Basically I want to have the error messages say, City 1 is required or
> > City is required etc.
>
> Theres nothing in Struts to do this - but I have an extension that
> can, availbale here:
>
> http://www.niallp.pwp.blueyonder.co.uk/strutsvalidatorextends.html#index
> ed
>
> Niall
>
> > I hope I was clear enough in my example.
> >
> > 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 <HC...@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
>
> ---------------------------------------------------------------------
> 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


RE: Validating list backed struts form

Posted by "Chaudhary, Harsh" <HC...@amfam.com>.
Thanks for all the tips Niall. Its working to the point that is possible
using Struts. Unfortunately, that does not solve my problem. And I
cannot use your extension as we have this thing about registered jars
here at work.

I guess a custom validator it is then.

Harsh.

-----Original Message-----
From: Niall Pemberton [mailto:niall.pemberton@gmail.com] 
Sent: Friday, February 09, 2007 9:46 AM
To: Struts Users Mailing List
Subject: Re: Validating list backed struts form


On 2/9/07, Chaudhary, Harsh <HC...@amfam.com> wrote:
> Thanks for the tip. I will try this out now. Another question though,
is
> it also possible to attach error messages for each  property depending
> on which property it is. An example would be:
>
> <form name="Customer">
>
>     <field property="city" indexedListProperty="addressList"
> depends="required">
>         <arg0 key="orderform.quantity.label[somethingHere]"/>
>     </field>
>
> </form>
>
> Basically I want to have the error messages say, City 1 is required or
> City is required etc.

Theres nothing in Struts to do this - but I have an extension that
can, availbale here:

http://www.niallp.pwp.blueyonder.co.uk/strutsvalidatorextends.html#index
ed

Niall

> I hope I was clear enough in my example.
>
> 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 <HC...@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

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


Re: Validating list backed struts form

Posted by Niall Pemberton <ni...@gmail.com>.
On 2/9/07, Chaudhary, Harsh <HC...@amfam.com> wrote:
> Thanks for the tip. I will try this out now. Another question though, is
> it also possible to attach error messages for each  property depending
> on which property it is. An example would be:
>
> <form name="Customer">
>
>     <field property="city" indexedListProperty="addressList"
> depends="required">
>         <arg0 key="orderform.quantity.label[somethingHere]"/>
>     </field>
>
> </form>
>
> Basically I want to have the error messages say, City 1 is required or
> City is required etc.

Theres nothing in Struts to do this - but I have an extension that
can, availbale here:

http://www.niallp.pwp.blueyonder.co.uk/strutsvalidatorextends.html#indexed

Niall

> I hope I was clear enough in my example.
>
> 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 <HC...@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


RE: Validating list backed struts form

Posted by "Chaudhary, Harsh" <HC...@amfam.com>.
Thanks for the tip. I will try this out now. Another question though, is
it also possible to attach error messages for each  property depending
on which property it is. An example would be:

<form name="Customer">

    <field property="city" indexedListProperty="addressList"
depends="required">
        <arg0 key="orderform.quantity.label[somethingHere]"/> 
    </field>
    
</form>

Basically I want to have the error messages say, City 1 is required or
City is required etc.

I hope I was clear enough in my example.

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 <HC...@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


RE: Validating list backed struts form

Posted by "Chaudhary, Harsh" <HC...@amfam.com>.
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">

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>

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 <HC...@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


Re: Validating list backed struts form

Posted by Niall Pemberton <ni...@gmail.com>.
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 <HC...@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