You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Cohan, Sean" <SC...@goSPS.com> on 2002/11/21 14:44:13 UTC

Index Based Names in Iterate Tag

I want to present a collection of beans using the <logic:iterate> tag.  One
of the fields in the collection is another collection of beans.  This second
collection of beans I want presented in an html select object.  In my Action
Class, I'd like to iterate through the first collection creating http
request attributes, each one containing an instance of the second
collection.  Something like this:

List list = (List) getList();
Iterator it = list.iterator();

for (i=1; it.hasNext(), i++) {
  MyBean myBean = (MyBean) it.next();
  request.setAttribute ("select"+ i, (List) myBean.getOtherList());
}

I want to use the <html:options> tag to populate the select objects.  The
collection parameter of <html:options> will have to the name of the
attributes created above (i.e., "select1", "select2", "select3",...)  

How can I create the collection name in each <html:options> tag in the jsp?
Can I use the indexId of the Iterate tag somehow to create it?  For example,
something like:

  <table border="0" cellpadding="0" cellspacing="0" >
  <logic:iterate ...>
    <tr> 
      <td>
         <html:select property="key">
           <html:options collection="select" + indexOf property="id"
labelProperty="description" />
         </html:select>
      </td>
    </tr>
  </logic:iterate> 
  </table>

I know my use of indexOf can't be right.  I'm just trying to show the idea
of what I'm trying to do.


Thanks.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Index Based Names in Iterate Tag

Posted by Patrice <pp...@nerim.net>.
I think that you can use a scriplet to define the property name:

<% String property = null; %>
<logic:iterate ... indexID="index">
    <html:select property="key">
        <% property = "select" + index; %>
        <html:options collection="<%= property %>" property="id"
labelProperty="description" />
    </html:select>
</logic:iterate>

Hope it helps
   Patrice

----- Original Message -----
From: "Cohan, Sean" <SC...@goSPS.com>
To: "Struts (E-mail)" <st...@jakarta.apache.org>
Sent: Thursday, November 21, 2002 2:44 PM
Subject: Index Based Names in Iterate Tag


> I want to present a collection of beans using the <logic:iterate> tag.
One
> of the fields in the collection is another collection of beans.  This
second
> collection of beans I want presented in an html select object.  In my
Action
> Class, I'd like to iterate through the first collection creating http
> request attributes, each one containing an instance of the second
> collection.  Something like this:
>
> List list = (List) getList();
> Iterator it = list.iterator();
>
> for (i=1; it.hasNext(), i++) {
>   MyBean myBean = (MyBean) it.next();
>   request.setAttribute ("select"+ i, (List) myBean.getOtherList());
> }
>
> I want to use the <html:options> tag to populate the select objects.  The
> collection parameter of <html:options> will have to the name of the
> attributes created above (i.e., "select1", "select2", "select3",...)
>
> How can I create the collection name in each <html:options> tag in the
jsp?
> Can I use the indexId of the Iterate tag somehow to create it?  For
example,
> something like:
>
>   <table border="0" cellpadding="0" cellspacing="0" >
>   <logic:iterate ...>
>     <tr>
>       <td>
>          <html:select property="key">
>            <html:options collection="select" + indexOf property="id"
> labelProperty="description" />
>          </html:select>
>       </td>
>     </tr>
>   </logic:iterate>
>   </table>
>
> I know my use of indexOf can't be right.  I'm just trying to show the idea
> of what I'm trying to do.
>
>
> Thanks.
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>