jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shawn Bayern <bay...@essentially.net>
Subject [PROPOSAL] Collections taglib
Date Sun, 21 Apr 2002 16:16:26 GMT
I mentioned this once before, but now that I have more time, I'd like to
explore it a little further.

Is there any interest for a taglib that manipulates objects from the Java
Collections API?  JSTL's expression language lets users read elements from
collections and iterate over them, but for more specialized operations
(computing the size, reversing the order, and so forth), users are on
their own.

While I was waiting for a session to start at JavaOne, I drafted up a
preliminary interface. Two questions, then --

 - Any interest in this, or is it pointless?
 - Does the interface (tag set) look reasonable as a starting point?


<data:copy var="new" collection="old" />
  // copies the collection, which is useful if you suspect it will change
  // or if you're going to modify it yourself

<data:size var="size" collection="c" />
  // computes and exposes the size of the collection

<data:sort var="new" collection="old" 
  // sorts the collection

<data:reverse var="new" collection="old" />
  // reverses the current order of the collection

<data:max var="max" collection="c" [comparator="c"] />
  // exposes the maximal element in the collection

<data:min var="min" collection="c" [comparator="c"] />
  // exposes the minimal element in the collection

<data:new collection="list|map|set" [javaType="..."]>
  // creates a new List, Map, or Set
  // - javaType if specified must be compatible with collection
  // - list defaults to ArrayList, map defaults to HashMap,
  //   set defaults to HashSet
  // - no 'collection' defaults to type suggested by subtags
  //   (key -> Map, no key -> List)
  // - empty <data:new> tag defaults to empty ArrayList.

  <data:item [value="value"] [key="key"] />
    // - no 'value' attribute implies String from body

  <data:items collection="c"/>


<data:add collection="c" >
  // adds the items from the subtags to the collection
  // - subtags must have a key if 'c' is a Map, otherwise must not
  <data:item .../>
  <data:items ... />


Use cases include:

  <data:reverse var="backwards" collection="${forwards}"/>
  <c:forEach items="${backwards}">


  <data:new var="new" scope="session">
    <data:items collection="${c1}"/>
    <data:items collection="${c2}"/>

  // elsewhere in session
  <c:forEach items="${new}">

Shawn Bayern
"JSP Standard Tag Library"  http://www.jstlbook.com
(coming this summer from Manning Publications)

To unsubscribe, e-mail:   <mailto:taglibs-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:taglibs-dev-help@jakarta.apache.org>

View raw message