You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Craig Dickson <cd...@aol.com> on 2004/09/08 18:51:03 UTC

[OT] How to sort with ?

Hi,

Is there an easy way to have the JSTL forEach tag sort the collection of
items before looping through them? Currently I have a scriptlet doing it
before the loop tag, but this is pretty ugly.

Thanks



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] How to sort with ?

Posted by Bill Siggelkow <bi...@bellsouth.net>.
Okay -- I don't know of a way to do this JSTL but you can do it with the 
display tags (this may have been already suggested). 
http://www.displaytag.org/example-sorting.jsp

-Bill Siggelkow

Craig Dickson wrote:
> I understand this suggestion. However, in the particular scenario I am 
> dealing with, the Collection is not part of the business layer.
> 
> For example, we want to print out the request headers on an error page 
> for debugging purposes. We want the headers to print out in name order 
> for ease of reading and finding specific headers in what is sometimes a 
> long list. Using JSTL with the built in EL, we could do something like this:
> 
>     <c:forEach items="${headers}" var="current">
>         <tr>
>             <td><c:out value="${current.name}"/></td>
>             <td><c:out value="${current.value}"/></td>
>         </tr>
>     </c:forEach>
> 
> In this case the value of "headers" is made available through the EL 
> (obviously I could grab the headers in a servlet prior to the JSP and 
> sort them and put them in the request, but we are trying to avoid all of 
> that hassle if possible).
> 
> This is just one example where having the tag itself to the sorting 
> would be advantageous.
> 
> 
> 
> Bill Siggelkow wrote on 9/8/2004, 10:23 AM:
> 
>  > Do it in the business layer that fetches the collection -- or in the
>  > database -- or store the data in a sorted collection (like SortedTreeMap
>  > or some similar animal).
>  >
>  > Craig Dickson wrote:
>  >
>  > > Hi,
>  > >
>  > > Is there an easy way to have the JSTL forEach tag sort the
>  > collection of
>  > > items before looping through them? Currently I have a scriptlet
>  > doing it
>  > > before the loop tag, but this is pretty ugly.
>  > >
>  > > Thanks
>  >
>  >
>  > ---------------------------------------------------------------------
>  > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>  > For additional commands, e-mail: user-help@struts.apache.org
>  >


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] How to sort with ?

Posted by Kris Schneider <kr...@dotech.com>.
The newer versions of the Display taglib (http://displaytag.sourceforge.net/)
appear to be EL-enabled, so perhaps it could help with a taglib-only sorting
solution.

Quoting Craig Dickson <cd...@aol.com>:

> I understand this suggestion. However, in the particular scenario I am 
> dealing with, the Collection is not part of the business layer.
> 
> For example, we want to print out the request headers on an error page 
> for debugging purposes. We want the headers to print out in name order 
> for ease of reading and finding specific headers in what is sometimes a 
> long list. Using JSTL with the built in EL, we could do something like this:
> 
>     <c:forEach items="${headers}" var="current">
>         <tr>
>             <td><c:out value="${current.name}"/></td>
>             <td><c:out value="${current.value}"/></td>
>         </tr>
>     </c:forEach>
> 
> In this case the value of "headers" is made available through the EL 
> (obviously I could grab the headers in a servlet prior to the JSP and 
> sort them and put them in the request, but we are trying to avoid all of 
> that hassle if possible).
> 
> This is just one example where having the tag itself to the sorting 
> would be advantageous.
> 
> 
> 
> Bill Siggelkow wrote on 9/8/2004, 10:23 AM:
> 
>  > Do it in the business layer that fetches the collection -- or in the
>  > database -- or store the data in a sorted collection (like SortedTreeMap
>  > or some similar animal).
>  >
>  > Craig Dickson wrote:
>  >
>  > > Hi,
>  > >
>  > > Is there an easy way to have the JSTL forEach tag sort the
>  > collection of
>  > > items before looping through them? Currently I have a scriptlet
>  > doing it
>  > > before the loop tag, but this is pretty ugly.
>  > >
>  > > Thanks

-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] How to sort with ?

Posted by Craig Dickson <cd...@aol.com>.
I understand this suggestion. However, in the particular scenario I am 
dealing with, the Collection is not part of the business layer.

For example, we want to print out the request headers on an error page 
for debugging purposes. We want the headers to print out in name order 
for ease of reading and finding specific headers in what is sometimes a 
long list. Using JSTL with the built in EL, we could do something like this:

    <c:forEach items="${headers}" var="current">
        <tr>
            <td><c:out value="${current.name}"/></td>
            <td><c:out value="${current.value}"/></td>
        </tr>
    </c:forEach>

In this case the value of "headers" is made available through the EL 
(obviously I could grab the headers in a servlet prior to the JSP and 
sort them and put them in the request, but we are trying to avoid all of 
that hassle if possible).

This is just one example where having the tag itself to the sorting 
would be advantageous.



Bill Siggelkow wrote on 9/8/2004, 10:23 AM:

 > Do it in the business layer that fetches the collection -- or in the
 > database -- or store the data in a sorted collection (like SortedTreeMap
 > or some similar animal).
 >
 > Craig Dickson wrote:
 >
 > > Hi,
 > >
 > > Is there an easy way to have the JSTL forEach tag sort the
 > collection of
 > > items before looping through them? Currently I have a scriptlet
 > doing it
 > > before the loop tag, but this is pretty ugly.
 > >
 > > Thanks
 >
 >
 > ---------------------------------------------------------------------
 > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
 > For additional commands, e-mail: user-help@struts.apache.org
 >



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] How to sort with ?

Posted by Bill Siggelkow <bi...@bellsouth.net>.
Do it in the business layer that fetches the collection -- or in the 
database -- or store the data in a sorted collection (like SortedTreeMap 
or some similar animal).

Craig Dickson wrote:

> Hi,
> 
> Is there an easy way to have the JSTL forEach tag sort the collection of
> items before looping through them? Currently I have a scriptlet doing it
> before the loop tag, but this is pretty ugly.
> 
> Thanks


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] How to sort with ?

Posted by Zoran Avtarovski <zo...@sparecreative.com>.
Hi Craig,

The displaytag taglib (displaytag.sf.net) already has this functionality and
supports el. Being open source you could also customise to your needs.

Zoran

> Hi,
> 
> Is there an easy way to have the JSTL forEach tag sort the collection of
> items before looping through them? Currently I have a scriptlet doing it
> before the loop tag, but this is pretty ugly.
> 
> Thanks
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org