You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by st...@stephan-wiesner.de on 2003/08/03 08:06:01 UTC
Iteration without Javacode
Hi list, I want to iterate over a number of rows from my database.
I have removed most of my Javacode, but two statements remain.
Any way I can get rid of those too?
<% BuchKatalog bk = new BuchKatalog(); %>
<ol>
<logic:iterate id="myBooks" collection="<%= bk.getBuecher() %>">
<li>
<bean:write name="myBooks" property="titel"/>
</li>
</logic:iterate>
</ol>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Iteration without Javacode
Posted by Mark Lowe <ma...@talk21.com>.
If the list is in an available context you can just use the name
attribute..
<%
java.util.ArrayList myList = new ArrayList();
myList.add("one");
myList.add("two");
pageContext.setAttribute("mylist",myList.toArray());
%>
<logic:iterate id="item" name="mylist">
<bean:write name="item" />
</logic:iterate>
Cheers mark
On Sunday, August 3, 2003, at 07:06 AM, <st...@stephan-wiesner.de>
wrote:
>
> Hi list, I want to iterate over a number of rows from my database.
> I have removed most of my Javacode, but two statements remain.
> Any way I can get rid of those too?
>
> <% BuchKatalog bk = new BuchKatalog(); %>
> <ol>
> <logic:iterate id="myBooks" collection="<%= bk.getBuecher() %>">
> <li>
> <bean:write name="myBooks" property="titel"/>
> </li>
> </logic:iterate>
> </ol>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Iteration without Javacode
Posted by David Graham <gr...@yahoo.com>.
--- stephan@stephan-wiesner.de wrote:
>
> Hi list, I want to iterate over a number of rows from my database.
> I have removed most of my Javacode, but two statements remain.
> Any way I can get rid of those too?
>
> <% BuchKatalog bk = new BuchKatalog(); %>
> <ol>
> <logic:iterate id="myBooks" collection="<%= bk.getBuecher() %>">
> <li>
> <bean:write name="myBooks" property="titel"/>
> </li>
> </logic:iterate>
> </ol>
1. Add this to your action:
request.setAttribute("books", (new BuchKatalog()).getBuecher());
2. Replace your JSP code with this:
<c:forEach var="book" items="${books}">
<c:out var="${book.titel}"/>
</c:forEach>
David
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org