You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Stephen Turner <st...@MIT.EDU> on 2009/09/25 20:03:50 UTC
Type Conversion and Lists
Hello,
I'm trying to get objects placed in a List using the type conversion
functionality built into Struts 2 (2.0.14)/Java 1.4. The bean that should
be in the list is called "Grocery", with attributes "name" and "quantity".
My action class has a List called "groceries".
I have a conversion properties file set up like this:
Element_groceries=mypackage.Grocery
The JSP has this:
<s:textfield name="groceries(0).name" label="Name" />
<s:textfield name="groceries(0).quantity" label="Quantity" />
<s:textfield name="groceries(1).name" label="Name" />
<s:textfield name="groceries(1).quantity" label="Quantity" />
If I fill in these values on the form,
Name: Apples
Quantity: 4
Name: Pears
Quantity: 8
I get 4 Grocery objects in the List, not 2:
Grocery obj 1: name=Apples, quantity=null
Grocery obj 2: name=null, quantity=4
Grocery obj 3: name=Pears, quantity=null
Grocery obj 4: name=null, quantity=8
What I want is two objects:
Grocery obj 1: name=Apples, quantity=4
Grocery obj 2: name=Pears, quantity=8
I thought the (0) and (1) in the JSP would tell the framework to do this,
but obviously not - it doesn't realize that the first two attributes (name
& quantity) should go into a single Grocery object.
Does anyone know the magic incantation to make this happen? I've studied
http://struts.apache.org/2.0.14/docs/type-conversion.html for hours
without success.
Thanks,
Steve
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Type Conversion and Lists
Posted by Dave Newton <ne...@yahoo.com>.
Stephen Turner wrote:
> Hello,
>
> I'm trying to get objects placed in a List using the type conversion
> functionality built into Struts 2 (2.0.14)/Java 1.4. The bean that
> should be in the list is called "Grocery", with attributes "name" and
> "quantity". My action class has a List called "groceries".
>
> I have a conversion properties file set up like this:
>
> Element_groceries=mypackage.Grocery
>
> The JSP has this:
>
> <s:textfield name="groceries(0).name" label="Name" />
> <s:textfield name="groceries(0).quantity" label="Quantity" />
> <s:textfield name="groceries(1).name" label="Name" />
> <s:textfield name="groceries(1).quantity" label="Quantity" />
Use brackets for arrays/lists.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org