You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Shamdasani Nimmi-ANS004 <AN...@motorola.com> on 2001/02/27 19:01:57 UTC

Question about iterate tag

Hi,

Could someone please tell me what I am doing wrong below:

user is a bean in session scope in my JSP and its getSuppliers() method returns a hashtable where keys are Suppliers Ids and elements are Supplier beans. 


<logic:iterate collection="<%= user.getSuppliers() %>" id="supplier" type="com.motorola.mms.msqc.beans.SupplierBean">

<TR>
<TD><bean:write name="supplier" property="seq_nbr" scope="page" /></TD>
<TD><bean:write name="supplier" property="name" scope="page" /></TD>
<TD><bean:write name="supplier" property="country_name" scope="page" /></TD>
</TR>

</logic:iterate>

Thanks in advance.

-Nimmi



Re: Question about iterate tag

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Shamdasani Nimmi-ANS004 wrote:

> Hi,
>
> Could someone please tell me what I am doing wrong below:
>
> user is a bean in session scope in my JSP and its getSuppliers() method returns a hashtable where keys are Suppliers Ids and elements are Supplier beans.
>
> <logic:iterate collection="<%= user.getSuppliers() %>" id="supplier" type="com.motorola.mms.msqc.beans.SupplierBean">
>
> <TR>
> <TD><bean:write name="supplier" property="seq_nbr" scope="page" /></TD>
> <TD><bean:write name="supplier" property="name" scope="page" /></TD>
> <TD><bean:write name="supplier" property="country_name" scope="page" /></TD>
> </TR>
>
> </logic:iterate>
>

When you iterate over a Hashtable (or any other implementation of the Map interface), the object get for the "id" variable is actually an implementation of
the "Map.Entry" class, not the class of the value of the bean.  From this "Map.Entry" instance, however, you can easily get to the real information:

    <bean:write name="supplier" property="value.seq_nbr" scope="page"/>

This works because a MapEntry has two properties -- key and value -- so we are using the nested property syntax to effectively call getValue().getSeq_nbr().

>
> Thanks in advance.
>
> -Nimmi

Craig