You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by mi...@lynx.de on 2001/02/14 17:43:37 UTC

iterate / bean write problem



Hello,

I'm struggling with a problem about iterate and bean write as used in the
example application.

I have an object OrderList which is registered as the attribute "orders". This
object contains
objects from the type Order (OrderList actually is an ArrayList). There is a
property getter method
for OrderList available which returns an array of Order objects (Order[]). It is
named getOrders().

So I want Struts to browse through the list of orders and display the properties
of each Order object
inside the list.

The portion of my JSP file looks like:

<table>
<logic:iterate name="orders" property="Orders" id="ord">
  <tr>
    <td align="left">
      <bean:write name="ord" property="ORDER_ID" filter="true"/>
    </td>
    <td align="left">
      <bean:write name="ord" property="RECEIVER_NAME" filter="true"/>
    </td>
  </tr>
</logic:iterate>
</table>


But when I run the application, I get the error message:

javax.servlet.ServletException: No bean found for attribute key ord
...


I think I have to register a bean for the Order objects, but I did not know how
to to it.
I have no idea what I have to do to get this running.

What do you suggest?

Regards

Michael






Re: iterate / bean write problem

Posted by Craig Tataryn <Cr...@msdw.com>.
Basically, when the "property" attribute is used with the logic:iterate tag, it
assumes that there is a jsp bean that you made available in your session named
<whatever value you specifed in the "name" attribute> and that this bean has a
property named <whatever value you used for the "property" attribute>, it then uses
this property as the object it will iterate through.

So in your example, the iterator is expected to be the  "orders.Orders" property
(you shouldn't capitalize the "O" on orders).  It also assumes that your "Order"
object has getters named getORDER_ID() and getREVEIVER_NAME().  If this is not the
case, and you really have getters of format getOrder_Id() and getReceiver_Name,
please use all lowercase characters for your bean:write property value (except for
letters that are actually capitialized in the getters excluding the first
character).

I think what you want to do is just get rid of the "property" attribute and change
your code to look like this:

<table>
<logic:iterate name="orders" id="ord">
  <tr>
    <td align="left">
      <bean:write name="ord" property="ORDER_ID" filter="true"/>
    </td>
    <td align="left">
      <bean:write name="ord" property="RECEIVER_NAME" filter="true"/>
    </td>
  </tr>
</logic:iterate>
</table>


michael.brohl@lynx.de wrote:

> Hello,
>
> I'm struggling with a problem about iterate and bean write as used in the
> example application.
>
> I have an object OrderList which is registered as the attribute "orders". This
> object contains
> objects from the type Order (OrderList actually is an ArrayList). There is a
> property getter method
> for OrderList available which returns an array of Order objects (Order[]). It is
> named getOrders().
>
> So I want Struts to browse through the list of orders and display the properties
> of each Order object
> inside the list.
>
> The portion of my JSP file looks like:
>
> <table>
> <logic:iterate name="orders" property="Orders" id="ord">
>   <tr>
>     <td align="left">
>       <bean:write name="ord" property="ORDER_ID" filter="true"/>
>     </td>
>     <td align="left">
>       <bean:write name="ord" property="RECEIVER_NAME" filter="true"/>
>     </td>
>   </tr>
> </logic:iterate>
> </table>
>
> But when I run the application, I get the error message:
>
> javax.servlet.ServletException: No bean found for attribute key ord
> ...
>
> I think I have to register a bean for the Order objects, but I did not know how
> to to it.
> I have no idea what I have to do to get this running.
>
> What do you suggest?
>
> Regards
>
> Michael

--
I've been trying to change the world for years, but they just won't give me the
source code....