File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes use c:forEach tag inside another c:forEach tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "use c:forEach tag inside another c:forEach tag" Watch "use c:forEach tag inside another c:forEach tag" New topic
Author

use c:forEach tag inside another c:forEach tag

Geraldine, Wang
Greenhorn

Joined: Jul 26, 2005
Posts: 2
Hi,
I've got en error when I tried to use <c:forEach> inside another <c:forEach> to display a vector of String arrays.

The error message is:
javax.servlet.ServletException: The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array, but that value cannot be converted to an integer.

The concerned section of the javabean mybean.java is:

//connect to database to get the resultset
...
ResultSet rs = cst.getResultSet();
if (rs != null) {
myVector = new Vector();
while (rs.next()) {
String myArray[] = new String[10];
myArray[0]=rs.getString(1);
myArray[1]=rs.getString(2);
...
myArray[9]=rs.getString(10);
myVector.addElement(myArray);
}
rs.close()
}
...

The concerned jsp calling the bean is:

<jsp:useBean id="theBean" scope="session" class="mybean" />
<jsp:setProperty name="theBean" property="..." />
<%
...
Vector myVector=theBean.getResultFromDatabaseIntomyVector();
pageContext.setAttribute("myVector",myVector);
%>
<table>
<c:forEach var = 'vectorItem' items='${myVector}'>
<tr>
<c:forEach var = 'arrayItem' items='${vectorItem.value}'>
<td><c ut value='${arrayItem}'/></td>
</c:forEach>
</tr>
</table>

Can anyone show me what's the right jsp for displaying a vector of String arrays?

Thanks in advance.
Geraldine
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

"Geraldine Geraldine",

There aren't may rules that have been put into place here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Geraldine, Wang
Greenhorn

Joined: Jul 26, 2005
Posts: 2
Hi all,

I've got the answer to this problem already. The correct jsp bit should be:

<table>
<c:forEach var = 'vectorItem' items='${myVector}'>
<tr>
<c:forEach var = 'arrayItem' items='${vectorItem}'>
<td><c out value='${arrayItem}'/></td>
</c:forEach>
</tr>
</c:forEach>
</table>
 
 
subject: use c:forEach tag inside another c:forEach tag