You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Nathan Maves <Na...@Sun.COM> on 2004/08/16 17:41:51 UTC

Difficult index properties problem

Here is the setup...


I have a 2 layered nested bean.

ie

Bean1 has n number of associated Bean2
Bean2 has n number of associated Bean3

I want to have a form that has an Array of Bean3's

Probem is that while iterating though Bean2's the count for the indexed 
property gets reset.  Any clever ideas to get around this.


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


Re: Difficult index properties problem

Posted by Nathan Maves <Na...@Sun.COM>.
or jsp 2.0!

On Aug 16, 2004, at 9:55 AM, Rick Reumann wrote:

> Rick Reumann wrote:
>
> Of course this assumes using html el tags.
>
>> <c:forEach items="${yourForm.listOf_A_Beans}" var="beanA"  
>> varStatus="beanAlistStatus">
>>     <html:text  
>> property="listOf_A_Beans[${beanAlistStatus.index}].name"  
>> value="${beanA.someProperty}" /><br>
>>     <c:forEach items="${beanA.listOf_B_Beans}" var="beanB"  
>> varStatus="beanBlistStatus">
>>        <html:text  
>> property="listOf_A_Beans[${beanAlistStatus.index}].listOf_B_Beans[${be 
>> anBlistStatus.index}].name" value="${beanB.someProperty}" /><br>
>>     </c:forEach>
>> </c:forEach>
>
>
> -- 
> Rick
>
> ---------------------------------------------------------------------
> 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: Difficult index properties problem

Posted by Rick Reumann <st...@reumann.net>.
Rick Reumann wrote:

Of course this assumes using html el tags.

> <c:forEach items="${yourForm.listOf_A_Beans}" var="beanA" 
> varStatus="beanAlistStatus">
>     <html:text property="listOf_A_Beans[${beanAlistStatus.index}].name" 
> value="${beanA.someProperty}" /><br>
>     <c:forEach items="${beanA.listOf_B_Beans}" var="beanB" 
> varStatus="beanBlistStatus">
>        <html:text 
> property="listOf_A_Beans[${beanAlistStatus.index}].listOf_B_Beans[${beanBlistStatus.index}].name" 
> value="${beanB.someProperty}" /><br>
>     </c:forEach>
> </c:forEach>
> 


-- 
Rick

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


Re: Difficult index properties problem

Posted by Rick Reumann <st...@reumann.net>.
Nathan Maves wrote:

> I have a 2 layered nested bean.
> 
> ie
> 
> Bean1 has n number of associated Bean2
> Bean2 has n number of associated Bean3
> 
> I want to have a form that has an Array of Bean3's
> 
> Probem is that while iterating though Bean2's the count for the indexed 
> property gets reset.  Any clever ideas to get around this.

I usually use the nested tag although JSTL works also but is a bit more 
verbose.
(could be some typos below .. this not tested)

Assume an ActionForm with a propety
Collection or List called listOf_A_Beans


<%-- Nested tag way --%>
<nested:iterate property="listOf_A_Beans">
     <nested:text property="someProperty" /><br>
     <nested:iterate property="listOf_B_Beans">
        <nested:text property="someProperty" /><br>
     </nested:iterate>
</nested:iterate>


<c:forEach items="${yourForm.listOf_A_Beans}" var="beanA" 
varStatus="beanAlistStatus">
     <html:text property="listOf_A_Beans[${beanAlistStatus.index}].name" 
value="${beanA.someProperty}" /><br>
     <c:forEach items="${beanA.listOf_B_Beans}" var="beanB" 
varStatus="beanBlistStatus">
        <html:text 
property="listOf_A_Beans[${beanAlistStatus.index}].listOf_B_Beans[${beanBlistStatus.index}].name" 
value="${beanB.someProperty}" /><br>
     </c:forEach>
</c:forEach>

-- 
Rick

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