I'm new to the list, but I've searched the bug list, Google, etc, and not
found a solution. However, as I'm fairly new to these things, I wanted to
raise it here for suggestions before submitting a bug report.
The problem is with c:forEach within a custom tag file. The custom tag
processing seems to do a 'toString()' on the attribute, so it's no longer a
Collection. The 'forEach' is then operating on a string, and it's
(deprecated) behaviour then is to comma-separate the string.
Using Tomcat 5.0.29, tested on Mac OS 10.3.5, latest Apple version of Java
1.4.2
Test case output is:
In test.jsp
str1
str2
str3
In utils:xyz.tag
first: [str1
other: str2
last: str3]
The JSP source is
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="utils" tagdir="/WEB-INF/tags/utils" %>
<!--
$Id$
@author David Stevenson
@author <a href="mailto:hoagy@ytfc.com">hoagy@ytfc.com</a>
@author <a target="_blank" href="http://www.confguide.com">Conference
Guide</a>
@version 1.0
@since SDK1.4
-->
<p class="subheader">In test.jsp</p>
<c:forEach items="${coll}" var="f">
<p>${f}</p>
</c:forEach>
<p class="subheader">In utils:xyz.tag</p>
<utils:xyz list="${coll}" />
The tag file source is:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ tag body-content="empty" %>
<%@ attribute name="list" required="true" rtexprvalue="true"%>
<c:forEach items="${list}" var="f" varStatus="s">
<c:choose>
<c:when test="${s.first}">first: </c:when>
<c:when test="${s.last}">last: </c:when>
<c:otherwise>other: </c:otherwise>
</c:choose>
${f}<br/>
</c:forEach>
The collection is built by a Struts action:
package com.confguide;
/**
* $Id$
*
* @author David Stevenson
* @author <a href="mailto:hoagy@ytfc.com">hoagy@ytfc.com</a>
* @author <a target="_blank" href="http://www.confguide.com">Conference
Guide</a>
* @version 1.0
* @since SDK1.4
*/
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.Cookie;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import java.util.logging.Logger;
import java.util.logging.Level;
import java.util.Collection;
import java.util.ArrayList;
public class TestAction extends Action {
private static Logger logger = Logger.getLogger("com.confguide");
public ActionForward execute ( ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
IOException, ServletException
{
Collection c = new ArrayList();
c.add("str1");
c.add("str2");
c.add("str3");
request.setAttribute("coll",c);
return mapping.findForward("ok");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
|