RE: Populating a DynaActionForm with a complex object graph

2004-02-03 Thread Doug Dixon
OK, I've starting off down the Map-backed, manual indexing route, and it's
grim... It forces me to have model logic in three places - the JSP (to
create the keys into the map) and the two action classes (prepopulate, then
handle submit).

Is there a more elegant way of doing this stuff? (Or are there any plans to
provide this functionality in future releases?)

Thanks
Doug

-Original Message-
From: Doug Dixon [mailto:[EMAIL PROTECTED]
Sent: 31 January 2004 11:50
To: '[EMAIL PROTECTED]'
Subject: Populating a DynaActionForm with a complex object graph


Hi

I'm trying to populate a DynaActionForm dynamically, using this how-to as a
starting point: http://www.developer.com/java/other/article.php/2233591

Because the number of elements in my form can vary at runtime, I take the
advice near the bottom of the article:

 You can even dynamically specify the size of the form (and 
prepopulate it) at run time [...] by using an Action instead of a 
forward to precreate the form-property value, and leaving the size 
parameter out.  The actual can then create an array of the appropriate 
size and prepopulate values..

So my Action instantiates the right number of beans in the form and then
hands off to the JSP, no problem. 

However, my model isn't a simple array (as in all the examples I can find) -
it's a complex object graph: I have one or more Flights, each of which can
contain one or more Passengers, each of which has multiple properties (name,
etc.)

This means I need another level of iteration, a bit like this (if it
worked!):


c:forEach var=flight items=${myBeanForm.map.flights} 
Flightbr/
c:forEach var=passenger items=${flight.passengers} 
   Passengerbr/
   Name: html:text indexed=true name=passenger property=name
/br/
/c:forEach
/c:forEach


This doesn't work - I just get HTML like this:

Flightbr/

Passengerbr/
Name: input type=text name=passenger[0].name value=Dougbr/


Flightbr/


Passengerbr/
Name: input type=text name=passenger[0].name
value=Elvisbr/


Which obviously won't work I need to end up with something like

Flightbr/

Passengerbr/
Name: input type=text name=flight[0].passenger[0].name
value=Dougbr/


Flightbr/


Passengerbr/
Name: input type=text name=flight[1].passenger[0].name
value=Elvisbr/



Does anyone know if there is some way of doing this with DynaActionForms? Or
am I going to have to do nasty manual indexing with Map or List backed
ActionForms?

Thanks for any help


This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk



This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Populating a DynaActionForm with a complex object graph

2004-02-03 Thread Adam Hardy
Hi Doug,
your title threw me off the scent a little but I think what you are 
looking for is nested beans.

HTH
Adam
On 02/03/2004 03:58 PM Doug Dixon wrote:
OK, I've starting off down the Map-backed, manual indexing route, and it's
grim... It forces me to have model logic in three places - the JSP (to
create the keys into the map) and the two action classes (prepopulate, then
handle submit).
Is there a more elegant way of doing this stuff? (Or are there any plans to
provide this functionality in future releases?)
Thanks
Doug
-Original Message-
From: Doug Dixon [mailto:[EMAIL PROTECTED]
Sent: 31 January 2004 11:50
To: '[EMAIL PROTECTED]'
Subject: Populating a DynaActionForm with a complex object graph
Hi

I'm trying to populate a DynaActionForm dynamically, using this how-to as a
starting point: http://www.developer.com/java/other/article.php/2233591
Because the number of elements in my form can vary at runtime, I take the
advice near the bottom of the article:
 You can even dynamically specify the size of the form (and 
prepopulate it) at run time [...] by using an Action instead of a 
forward to precreate the form-property value, and leaving the size 
parameter out.  The actual can then create an array of the appropriate 
size and prepopulate values..

So my Action instantiates the right number of beans in the form and then
hands off to the JSP, no problem. 

However, my model isn't a simple array (as in all the examples I can find) -
it's a complex object graph: I have one or more Flights, each of which can
contain one or more Passengers, each of which has multiple properties (name,
etc.)
This means I need another level of iteration, a bit like this (if it
worked!):
c:forEach var=flight items=${myBeanForm.map.flights} 
Flightbr/
c:forEach var=passenger items=${flight.passengers} 
   Passengerbr/
   Name: html:text indexed=true name=passenger property=name
/br/
/c:forEach
/c:forEach
This doesn't work - I just get HTML like this:

Flightbr/

Passengerbr/
Name: input type=text name=passenger[0].name value=Dougbr/


Flightbr/


Passengerbr/
Name: input type=text name=passenger[0].name
value=Elvisbr/

Which obviously won't work I need to end up with something like

Flightbr/

Passengerbr/
Name: input type=text name=flight[0].passenger[0].name
value=Dougbr/


Flightbr/


Passengerbr/
Name: input type=text name=flight[1].passenger[0].name
value=Elvisbr/



Does anyone know if there is some way of doing this with DynaActionForms? Or
am I going to have to do nasty manual indexing with Map or List backed
ActionForms?
--
struts 1.1 + tomcat 5.0.16 + java 1.4.2
Linux 2.4.20 Debian
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Populating a DynaActionForm with a complex object graph

2004-01-31 Thread Doug Dixon
Hi

I'm trying to populate a DynaActionForm dynamically, using this how-to as a
starting point: http://www.developer.com/java/other/article.php/2233591

Because the number of elements in my form can vary at runtime, I take the
advice near the bottom of the article:

 You can even dynamically specify the size of the form (and 
prepopulate it) at run time [...] by using an Action instead of a 
forward to precreate the form-property value, and leaving the size 
parameter out.  The actual can then create an array of the appropriate 
size and prepopulate values..

So my Action instantiates the right number of beans in the form and then
hands off to the JSP, no problem. 

However, my model isn't a simple array (as in all the examples I can find) -
it's a complex object graph: I have one or more Flights, each of which can
contain one or more Passengers, each of which has multiple properties (name,
etc.)

This means I need another level of iteration, a bit like this (if it
worked!):


c:forEach var=flight items=${myBeanForm.map.flights} 
Flightbr/
c:forEach var=passenger items=${flight.passengers} 
   Passengerbr/
   Name: html:text indexed=true name=passenger property=name
/br/
/c:forEach
/c:forEach


This doesn't work - I just get HTML like this:

Flightbr/

Passengerbr/
Name: input type=text name=passenger[0].name value=Dougbr/


Flightbr/


Passengerbr/
Name: input type=text name=passenger[0].name
value=Elvisbr/


Which obviously won't work I need to end up with something like

Flightbr/

Passengerbr/
Name: input type=text name=flight[0].passenger[0].name
value=Dougbr/


Flightbr/


Passengerbr/
Name: input type=text name=flight[1].passenger[0].name
value=Elvisbr/



Does anyone know if there is some way of doing this with DynaActionForms? Or
am I going to have to do nasty manual indexing with Map or List backed
ActionForms?

Thanks for any help


This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]