[prev in list] [next in list] [prev in thread] [next in thread] 

List:       struts-user
Subject:    Populating a DynaActionForm with a complex object graph
From:       Doug Dixon <ddixon () Lastminute ! com>
Date:       2004-01-31 11:50:15
Message-ID: A9F75F9AB514D611A69D0002A5AD9BED11793BBE () lmnukex05 ! lastminute ! com
[Download RAW message or body]

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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic