Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JSP Interest »

Re: Jsp 2, tag files and collections...

Erik Beijnoff

2004-02-24

Replies:

>I have several pages in my app that display a list of items
>and I want to format them all in the same way - but each
>page displays different things.

>So I could have the foreach loop on each page, but then I
>would be repeating the wrapper formatting on each page too.

>By using the tag file, I put the standard formatting in there.

>My workaround has been to use c:set to set a "global" variable
>before calling the tagfile and then using it internally.

I almost guessed that was the reason you wanted to create a specifik
tag.

Could it be that you try to iterate over a Map? Afaik a Map value is
accessed in a fashion different from Lists. You must reference the
values in the Map on the form ${var.value} where a List value is
accessed just as ${var}. From there on the get for example the
Person.getName() you should be able to say ${var.value.name}.

------------------------------------------------------------------
Example 1:
<c:forEach items="${myMap}" var="m">
    Key: ${m.key} Value: ${m.value}
</c:forEach>

<c:forEach items="${myList}" var="l">
    Value: ${l}
</c:forEach>
------------------------------------------------------------------
Example 2 (tag):
<?xml version="1.0" encoding="UTF-8"?>

<jsp:root
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:tags="urn:jsptagdir:/WEB-INF/tags"
version="2.0">

<jsp:directive.attribute     name="objects"
                          type="java.lang.Object"
                          required="true"/>


<!-- Start the tag rendering -->
<c:forEach items="${objects}" var="item">
    Value: ${item}
</c:forEach>
</jsp:root>

===========================================================================
To unsubscribe: mailto listserv@(protected)".
For digest: mailto listserv@(protected)".

Some relevant archives, FAQs and Forums on JSPs can be found at:

http://java.sun.com/products/jsp
http://archives.java.sun.com/jsp-interest.html
http://forums.java.sun.com
http://www.jspinsider.com


©2008 junlu.com - Jax Systems, LLC, U.S.A.