Friday, September 26, 2008

JSF1.2 and JSP2.1 unified EL not fully Integrated

I need to iterate through a List in a ListDataModel object using JSF 1.2 with JSP2.1 and JSTL 1.2. I was hoping to leverage the integration via the Unified EL. The following java.net FAQ made this sound promising.

BTW: I'm using Seam 2.0.2sp1 to make JSF integration with backing bean easier.

Here's my backing bean:
@Name("test")
@Scope(ScopeType.CONVERSATION)
public class Test implements Serializable {

/**
*
*/
private static final long serialVersionUID = 7261056085418809473L;

@DataModel
private List> items;

@Factory(value="items")
public void findItems() {
items = new ArrayList>();
List first=new ArrayList();
first.add("fvalue1");
first.add("fValue2");
first.add("fvalue3");
items.add(first);
List second=new ArrayList();
second.add("svalue1");
second.add("sValue2");
second.add("svalue3");
items.add(second);
}
}


And Here's my JSP page:


<?xml version="1.0"?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns="http://www.w3.org/1999/xhtml"
version="2.1">
<jsp:output doctype-root-element="html"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3c.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<jsp:directive.page contenttype="text/html">
<html>
<head>
<title>Test</title>
</head>
<body>
<h1>Test</h1>

<f:view>
<table>
<c:foreach items="#{items.wrappedData}" var="_item">
<c:foreach items="#{_item}" var="val">
<tr><td>
<h:outputtext value="#{val}"></h:outputText>
</td></tr>
</c:forEach>
</c:forEach>
</table>

</f:view>
</body>
</html>
</jsp:root>


This works and produces the following results:


fvalue1
fValue2
fvalue3
svalue1
sValue2
svalue3


Which is exactly what I want, but when I do the following it fails.

<?xml version="1.0"?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns="http://www.w3.org/1999/xhtml"
version="2.1">
<jsp:output doctype-root-element="html"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3c.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<jsp:directive.page contenttype="text/html">
<html>
<head>
<title>Test</title>
</head>
<body>
<h1>Test</h1>

<f:view>
<table>
<c:foreach items="#{items.wrappedData}" var="_item">
<c:foreach items="#{_item}" var="val">
<tr><td>
<h:outputtext value="#{val}"></h:outputText>
</td></tr>
</c:forEach>
</c:forEach>
</table>

</f:view>
</body>
</html>
</jsp:root>

This fails with the following exception:
root cause

javax.servlet.ServletException: javax.servlet.jsp.JspTagException:
Don't know how to iterate over supplied "items" in &lt;forEach&gt;
org.apache.jasper.runtime.PageContextImpl.doHandlePageException
(PageContextImpl.java:850)


So, it seams you can not access the referenced #{_item} in the
forEach.