struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Turner" <stur...@MIT.EDU>
Subject Type Conversion and Lists
Date Fri, 25 Sep 2009 18:03:50 GMT

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:


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 for hours  
without success.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message