You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Claus M. Christiansen" <a...@skjern-net.dk> on 2004/10/12 21:13:31 UTC

Nested tags

Hi ML...

I have kind of a problem which I just can't get solved!

I have an iterate tag inside an iterate tag, but in the nested iterate 
tag I need the indexed value from the outer iterate tag!!

I have:

<html:form action="/storeCombiQuestion.do">
    <logic:present name="subQuestions" scope="session">
        <logic:iterate name="subQuestions" id="question" 
indexId="subQuestion">
           <bean:write name="question" property="text" />
           <logic:match name="question" value="SingleChoice" >
             <logic:iterate name="question" property="possibleChoices" 
id="option" type="dk.procore.model.Option">
                 <html:radio property="answer" 
value="<%=option.getOption()%>" indexed="true">
                     <bean:write name="option" property="option" />
                 </html:radio>
              </logic:iterate>
              <br />
            </logic:match>
        </logic:iterate>
    </logic:present>
    <html:submit />
</html:form>

Now.. The problem lies in the nested iterate tag. The "indexed=true" 
takes the value from the iterate tag in which it is nested, but what I 
really need is the one from the outer tag, which is called subQuestion. 
The reason I need the 'outer' is because the <html:radio is dependant on it.
I'm not even sure it can be done this way, but if it can't then I would 
like a suggestion of what to do then...

Thanks in advance...

Claus

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


Re: Nested tags

Posted by "Claus M. Christiansen" <a...@skjern-net.dk>.
>
> just use whatever id you are using for the indexId of the outer nested 
> iterate.
>
> <nested:iterate property="outer" indexId="fooIndex">
>     <nested:iterate property="inner" indexId="barIndex">
>
> if you are using the nested EL tags or JSP2.0 you then have easy 
> access to display the value of any indexId ... use either <c:out 
> value='${fooIndex}'/> if JSTL or if JSP2.0 just ${fooIndex}
>
>
The problem is not so much that I want to display it, cause that can 
also be done with <bean:write> tag, but I would like to use the outer 
index value for the <html:radio ... indexed="true" />. The generated 
HTML page looks like this

 <input type="radio" name="org.apache.struts.taglib.html.BEAN[1].answer" value="00">00
 <input type="radio" name="org.apache.struts.taglib.html.BEAN[2].answer" value="03">03

 <input type="radio" name="org.apache.struts.taglib.html.BEAN[1].answer" value="00">00
 <input type="radio" name="org.apache.struts.taglib.html.BEAN[2].answer" value="03">03

and so on. The number in BEAN[n] is the "wrong" one. It should be the same one in the first two and in the second two like this:
 <input type="radio" name="org.apache.struts.taglib.html.BEAN[1].answer" value="00">00
 <input type="radio" name="org.apache.struts.taglib.html.BEAN[1].answer" value="00">00

 <input type="radio" name="org.apache.struts.taglib.html.BEAN[2].answer" value="03">03
 <input type="radio" name="org.apache.struts.taglib.html.BEAN[2].answer" value="03">03

So the outer indexId, fooIndex, should be the one replacing 'n' in BEAN[n] instead of barIndex.

Claus


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


Re: Nested tags

Posted by Rick Reumann <st...@reumann.net>.
Claus M. Christiansen wrote the following on 10/12/2004 3:13 PM:

> Now.. The problem lies in the nested iterate tag. The "indexed=true" 
> takes the value from the iterate tag in which it is nested, but what I 
> really need is the one from the outer tag, which is called subQuestion. 
> The reason I need the 'outer' is because the <html:radio is dependant on 
> it.
> I'm not even sure it can be done this way, but if it can't then I would 
> like a suggestion of what to do then...

just use whatever id you are using for the indexId of the outer nested 
iterate.

<nested:iterate property="outer" indexId="fooIndex">
	<nested:iterate property="inner" indexId="barIndex">

if you are using the nested EL tags or JSP2.0 you then have easy access 
to display the value of any indexId ... use either <c:out 
value='${fooIndex}'/> if JSTL or if JSP2.0 just ${fooIndex}


-- 
Rick

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