I haven't played with netsted tags for a while, I always preferred seeing where in indexed properties were. I have to confess it completely escaped my attention.

Mark

On 25 Jun 2004, at 13:55, René Zbinden wrote:

I'm not sure if i got the problem correctly. But have a look at the nested taglib too. Could make your jsp easier but renders to the same as below.
http://jakarta.apache.org/struts/userGuide/struts-nested.html


http://www.keyboardmonkey.com/next/index.jsp

Hope it's of any use to you
René


-----Ursprüngliche Nachricht-----
Von: Mark Lowe [mailto:[EMAIL PROTECTED]
Gesendet: Freitag, 25. Juni 2004 09:33
An: Struts Users Mailing List
Betreff: Re: 2 deep nested forms (solution to 2 dimensional arrays with struts html tags)


No i was wrong works as i thought it would

Need to iterate through the values of the dishes map

public Object[] getDishes() {
        return map.values().toArray();
}


<%-- var could be anything the index us the important bit --%> <c:forEach var="dish" items="${course.dishes}" varStatus="index">
<%-- get the correctly indexed key from the getKeys array-%> <c:set var="key" value="${course.keys[index.count - 1]}" /> <html:text name="course" property="dish(${key}.name" indexed="true" /> </c:forEach>


renders to


<input type="text" name="course[0].dish(key1).name" value="Fish">

<input type="text" name="course[0].dish(key2).name" value="More Fish">

On 25 Jun 2004, at 01:09, Mark Lowe wrote:

No needs a rethink .

indexed="true" uses whatever iteration tags that its between.. Arses,,
drat and double drat.



On 25 Jun 2004, at 00:27, Mark Lowe wrote:

Not quite.. hang on.



On 25 Jun 2004, at 00:14, Mark Lowe wrote:

A question came up the other week/month where someone nesting 2 deep
and was trying to use a 2 dimesional array. I had the some problem
today and had my chance to combine indexed and mapped properties to
solve the problem.

I want to create a Restaurant Menu editor. So a menu has a few
properties like title and start and end dates for seasonal menus.

So I have 3 action form or nested pojo's


MenuForm CourseForm DishBean

I used lazyMap and lazyList to save scoping to session.


MenuForm - has a lazyList or nested courses. CourseForm - has a lazyMap of dishes and a getKeys() method that returns map.keySet().toArray()

and dishes are just plain string properties.

public DishBean getDish(String key)

public void setDish(String key,DishBean dish)

The jsp stuff looks something like this.

<html:text property="title" />

<c:forEach var="course" items="${menuForm.courses}">
        <html:text name="course" property="title" indexed="true" />
        
        <c:forEach var="key" items="${course.keys}">
                <html:text name="course" property="dish(${key}).name"
indexed="true" />
        </c:forEach>

</c:forEach>

its not quite as tidy as 2 dimensional array support, but it pretty
clean looking.



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



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



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



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




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



Reply via email to