Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <a href="https://stackoverflow.com/tags/el/info">SO EL Tag Wiki</a> describes a way to do this without using a scriptlet: using an EL function to do the sort, then using the result for the <code>items</code> attribute in the JSTL core <code>forEach</code> tag.</p> <p>The function class:</p> <pre><code>package org.hierax.ifdl.tags.player; public final class PlayerSort { public static List&lt;Player&gt; sortByRank(List&lt;Player&gt; playerList) { Collections.sort(playerList, new PlayerSortByRank()); return playerList; } public static List&lt;Player&gt; sortByAlias(List&lt;Player&gt; playerList) { Collections.sort(playerList, new PlayerSortByAlias()); return playerList; } } </code></pre> <p>The TLD:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt; &lt;taglib xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd" version="2.1"&gt; &lt;display-name&gt;Player Functions&lt;/display-name&gt; &lt;tlib-version&gt;1.0&lt;/tlib-version&gt; &lt;short-name&gt;player&lt;/short-name&gt; &lt;uri&gt;org.hierax.ifdl.tags&lt;/uri&gt; &lt;function&gt; &lt;name&gt;sortByRank&lt;/name&gt; &lt;function-class&gt;org.hierax.ifdl.tags.player.PlayerSort&lt;/function-class&gt; &lt;function-signature&gt;java.util.List sortByRank(java.util.List)&lt;/function-signature&gt; &lt;/function&gt; &lt;function&gt; &lt;name&gt;sortByAlias&lt;/name&gt; &lt;function-class&gt;org.hierax.ifdl.tags.player.PlayerSort&lt;/function-class&gt; &lt;function-signature&gt;java.util.List sortByAlias(java.util.List)&lt;/function-signature&gt; &lt;/function&gt; &lt;/taglib&gt; </code></pre> <p>The menu JSP:</p> <pre><code>&lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt; &lt;%@ taglib prefix="p" uri="/WEB-INF/player.tld" %&gt; &lt;h1&gt;Players&lt;/h1&gt; &lt;p&gt; &lt;c:forEach items="${p:sortByAlias(model.players)}" var="player"&gt; &lt;a href="&lt;c:url value="/player/${player.id}"/&gt;" class="menuItem"&gt;${player.alias}&lt;/a&gt; &lt;/c:forEach&gt; &lt;/p&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload