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:ddixon@Lastminute.com]
Sent: 31 January 2004 11:50
To: 'struts-user@jakarta.apache.org'
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}" >
Flight<br/>
<c:forEach var="passenger" items="${flight.passengers}" >
Passenger<br/>
Name: <html:text indexed="true" name="passenger" property="name"
/><br/>
</c:forEach>
</c:forEach>
This doesn't work - I just get HTML like this:
Flight<br/>
Passenger<br/>
Name: <input type="text" name="passenger[0].name" value="Doug"><br/>
Flight<br/>
Passenger<br/>
Name: <input type="text" name="passenger[0].name"
value="Elvis"><br/>
Which obviously won't work.... I need to end up with something like
Flight<br/>
Passenger<br/>
Name: <input type="text" name="flight[0].passenger[0].name"
value="Doug"><br/>
Flight<br/>
Passenger<br/>
Name: <input type="text" name="flight[1].passenger[0].name"
value="Elvis"><br/>
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: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
________________________________________________________________________
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: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
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:ddixon@Lastminute.com]
> Sent: 31 January 2004 11:50
> To: 'struts-user@jakarta.apache.org'
> 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}" >
> Flight<br/>
> <c:forEach var="passenger" items="${flight.passengers}" >
> Passenger<br/>
> Name: <html:text indexed="true" name="passenger" property="name"
> /><br/>
> </c:forEach>
> </c:forEach>
>
>
> This doesn't work - I just get HTML like this:
>
> Flight<br/>
>
> Passenger<br/>
> Name: <input type="text" name="passenger[0].name" value="Doug"><br/>
>
>
> Flight<br/>
>
>
> Passenger<br/>
> Name: <input type="text" name="passenger[0].name"
> value="Elvis"><br/>
>
>
> Which obviously won't work.... I need to end up with something like
>
> Flight<br/>
>
> Passenger<br/>
> Name: <input type="text" name="flight[0].passenger[0].name"
> value="Doug"><br/>
>
>
> Flight<br/>
>
>
> Passenger<br/>
> Name: <input type="text" name="flight[1].passenger[0].name"
> value="Elvis"><br/>
>
>
>
> 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: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org