> Have your backend Jaca code return a collection of BookBean. It is
> very easy to iterate over that.
thanks.
I tried that before, but I don't know how to iterate the list of beans
in my servlet I did:
List list = (List) session.getAttribute("pageList");
if (list == null)
{
list = new ArrayList();
PageListBean page1 = new PageListBean("HTML Beginner",
"/beginner.jsp");
PageListBean page2 = new PageListBean("HTML Pro", "/pro.jsp");
list.add(page1);
list.add(page2);
session.setAttribute("pageList", list);
}
then I tried to retrieve the list of beans but I couldn't have the JSP page
working iterating, can you please say how? thanks
<jsp:useBean id="pageList" type="p4Solution.PageBean" scope="session" />
.........

Signature
ciao
Vittorix
Vittorix - 09 Mar 2008 20:56 GMT
> then I tried to retrieve the list of beans but I couldn't have the
> JSP page working
trying and retrying, but still not working.
in the PageBean class I did
private List items = new ArrayList( );
public List getItems() {
return items;
}
public void setItems(List items) {
this.items = items;
}
in my servlet I did:
List list = (List) session.getAttribute("pageList");
if (list == null)
{
list = new ArrayList();
PageListBean page1 = new PageListBean("HTML Beginner",
"/beginner.jsp");
PageListBean page2 = new PageListBean("HTML Pro", "/pro.jsp");
list.add(page1);
list.add(page2);
session.setAttribute("pageList", list);
}
then I tried to retrieve the list of beans:
<jsp:useBean id="pageList" type="p4Solution.PageBean" scope="session" />
<c:set var="itemsList" value="${ pageList.items }" />
<UL>
<c:forEach var="item" items="${pageList.items}">
<LI>${item}</LI>
</c:forEach>
but I couldn't have the JSP page working

Signature
ciao
Vittorix
Arne Vajhøj - 09 Mar 2008 20:56 GMT
>> Have your backend Jaca code return a collection of BookBean. It is
>> very easy to iterate over that.
>
> I tried that before, but I don't know how to iterate the list of beans
[example from a contact page - you should easily be able
to translate to books]
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
...
<table border>
<tr>
<th>Navn</th>
<th>Telefon</th>
<th>Email</th>
</tr>
<c:forEach var="c" items="${allc}">
<tr>
<td><c:out value="${c.name}"/></td>
<td><c:out value="${c.phone}"/></td>
<td><c:out value="${c.email}"/></td>
<tr>
</c:forEach>
</table>
The above just assume that request has an attribute under the
name "allc" that is a collection of a bean class with name,
phone and email properties.
Arne
PS: It is not even utilizing JSP 2.0 !
Vittorix - 09 Mar 2008 23:35 GMT
> [example from a contact page - you should easily be able
> to translate to books]
I'm trying this, but it doesn't work :(
########### INSIDE THE SERVLET:
List list = (List) request.getAttribute("allc");
if (list == null)
{
list = new ArrayList();
Bean b1 = new Bean("Vittorio", "123", "email1");
Bean b2 = new Bean("Arne", "345", "email2");
Bean b3 = new Bean("Barne", "567", "email3");
Bean b4 = new Bean("Carne", "789", "email4");
list.add(b1);
list.add(b2);
list.add(b3);
list.add(b4);
request.setAttribute("allc", list);
}
RequestDispatcher dispatcher =
request.getRequestDispatcher("/p4Solution/echart.jsp");
dispatcher.forward(request, response);
######## JSP PAGE
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%--
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
--%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h2>Your Shopping Cart</h2>
<table border>
<tr>
<th>Navn</th>
<th>Telefon</th>
<th>Email</th>
</tr>
<c:forEach var="c" items="${allc}">
<tr>
<td><c:out value="${c.name}"/></td>
<td><c:out value="${c.phone}"/></td>
<td><c:out value="${c.email}"/></td>
<tr>
</c:forEach>
</table>
</body>
</html>

Signature
ciao
Vittorix
Arne Vajhøj - 10 Mar 2008 00:48 GMT
>> [example from a contact page - you should easily be able
>> to translate to books]
>
> I'm trying this, but it doesn't work :(
Care to reveal what the error is ?
Arne
Vittorix - 10 Mar 2008 01:23 GMT
>>> [example from a contact page - you should easily be able
>>> to translate to books]
>>
>> I'm trying this, but it doesn't work :(
>
> Care to reveal what the error is ?
no error the page compiles fine, it just doesn't show anything, only the
table headers :(

Signature
ciao
Vittorix
Arne Vajhøj - 10 Mar 2008 02:32 GMT
>>>> [example from a contact page - you should easily be able
>>>> to translate to books]
[quoted text clipped - 3 lines]
> no error the page compiles fine, it just doesn't show anything, only the
> table headers :(
Sounds as if the content of the list is somehow lost.
Try put in some debug print in the JSP page to check
if the list actually contains something there.
Arne
Vittorix - 10 Mar 2008 17:23 GMT
>>>>> [example from a contact page - you should easily be able
>>>>> to translate to books]
[quoted text clipped - 8 lines]
> Try put in some debug print in the JSP page to check
> if the list actually contains something there.
because I couldn't find a solution, I'm using a scriplet inside the JSP that
does the job:
int numBooks = Integer.parseInt(request.getParameter("numBook"));
for (int i=1; i<=numBooks; i++)
{
String bookBeanS = "bookBeanBeg" + i + "";
p4Solution.BookBean bookBean = null;
bookBean = (p4Solution.BookBean) session.getAttribute(bookBeanS);
out.write(bookBean.getSeq_no());
thanks anyway.

Signature
ciao
Vittorix