Shawn Bayern wrote:
> On Thu, 15 Aug 2002, Þorgils Völundarson wrote:
> 
> 
>>how can I store multiple data items from jstl xml query in a vector to
>>be used later in a servlet to f.x. sort the data?
> 
> 
> I'm not sure what "f.x." means, but in general, this sort of operation is
> probably best performed entirely in a servlet.  Servlets are better suited
> than JSTL for building and performing complex operations on data
> structures.

I agree with Shawn that complex code should go in some other type of
component, but for simple sorts I sometimes use this trick:

   <%-- Create a TreeMap: it sorts its keys automatically --%>
   <jsp:useBean id="sorted" class="java.util.TreeMap" />

   <%-- Add the values to be sorted as keys in the TreeMap --%>
   <c:set target="${sorted}" property="z" value="" />
   <c:set target="${sorted}" property="b" value="" />
   <c:set target="${sorted}" property="x" value="" />

   <%-- Use the sorted keys --%>
   <c:forEach items="${sorted}" var="c">
     <c:out value="${c.key}" />
   </c:forEach>

Hans
-- 
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com
JavaServer Pages        http://TheJSPBook.com


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to