tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Stevenson <>
Subject c:forEach within custom tag definition
Date Thu, 28 Oct 2004 01:46:11 GMT
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

Test case output is:

In test.jsp




In utils:xyz.tag
 first: [str1
 other: str2
 last: str3]

The JSP source is
<%@ taglib prefix="c"        uri="" %>
<%@ taglib prefix="utils"    tagdir="/WEB-INF/tags/utils" %>

  @author David Stevenson
  @author <a href=""></a>
  @author <a target="_blank" href="">Conference
  @version 1.0 
  @since SDK1.4
<p class="subheader">In test.jsp</p>

<c:forEach items="${coll}" var="f">

<p class="subheader">In utils:xyz.tag</p>
<utils:xyz list="${coll}" />

The tag file source is:
<%@ taglib uri="" prefix="c" %>
<%@ taglib uri="" prefix="fn" %>

<%@ tag body-content="empty" %>

<%@ attribute name="list" required="true" rtexprvalue="true"%>

<c:forEach items="${list}" var="f" varStatus="s">
    <c:when test="${s.first}">first: </c:when>
    <c:when test="${s.last}">last: </c:when>
    <c:otherwise>other: </c:otherwise>

The collection is built by a Struts action:
package com.confguide;

* $Id$
 * @author David Stevenson
 * @author <a href=""></a>
 * @author <a target="_blank" href="">Conference
 * @version 1.0 
 * @since SDK1.4

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();
        return mapping.findForward("ok");

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message