You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mark Lowe <ma...@boxstuff.com> on 2004/06/25 00:14:47 UTC

2 deep nested forms (solution to 2 dimensional arrays with struts html tags)

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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: 2 deep nested forms (solution to 2 dimensional arrays with struts html tags)

Posted by Mark Lowe <ma...@boxstuff.com>.
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: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: 2 deep nested forms (solution to 2 dimensional arrays with struts html tags)

Posted by Mark Lowe <ma...@boxstuff.com>.
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: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: 2 deep nested forms (solution to 2 dimensional arrays with struts html tags)

Posted by Mark Lowe <ma...@boxstuff.com>.
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: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org