You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by js...@apache.org on 2002/01/18 19:44:02 UTC

cvs commit: jakarta-taglibs/xtags/xml xtags.xml

jstrachan    02/01/18 10:44:02

  Modified:    xtags/src/org/apache/taglibs/xtags/xpath ForEachTag.java
               xtags/xml xtags.xml
  Added:       xtags/examples/web/test test_for_each_sort.jsp
  Log:
  Added new sorting option for the xtags:forEach tag which allows sorting to be in either ascending or descending order
  
  Revision  Changes    Path
  1.1                  jakarta-taglibs/xtags/examples/web/test/test_for_each_sort.jsp
  
  Index: test_for_each_sort.jsp
  ===================================================================
  <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
  <html>
  <%@ taglib uri="http://jakarta.apache.org/taglibs/xtags-1.0" prefix="xtags" %>
  
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  <title>Test ForEach Sorting</title>
  </head>
  
  <body>
  
  <xtags:parse id="doc">      
    <%@ include file="/periodic_table.xml" %>
  </xtags:parse>
  
  <h1>Ascending order</h1>
  
  <xtags:forEach select="//ATOM" sort="NAME">
  <p>
    <xtags:valueOf select="NAME"/> 
    :
    <xtags:valueOf select="SYMBOL"/>
  </p>
  </xtags:forEach>
  
  <hr/>
  
  
  <h1>Ascending order #2</h1>
  
  <xtags:forEach select="//ATOM" sort="NAME" ascending="true">
  <p>
    <xtags:valueOf select="NAME"/> 
    :
    <xtags:valueOf select="SYMBOL"/>
  </p>
  </xtags:forEach>
  
  <hr/>
  
  
  <h1>Descending order</h1>
  
  <xtags:forEach select="//ATOM" sort="NAME" ascending="false">
  <p>
    <xtags:valueOf select="NAME"/> 
    :
    <xtags:valueOf select="SYMBOL"/>
  </p>
  </xtags:forEach>
  
  <hr/>
  
  </body>
  </html>
  
  
  1.2       +22 -1     jakarta-taglibs/xtags/src/org/apache/taglibs/xtags/xpath/ForEachTag.java
  
  Index: ForEachTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/xtags/src/org/apache/taglibs/xtags/xpath/ForEachTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ForEachTag.java	24 Jul 2001 13:44:22 -0000	1.1
  +++ ForEachTag.java	18 Jan 2002 18:44:02 -0000	1.2
  @@ -108,6 +108,8 @@
       /** Cache of original context which is restored after the loop finishes */
       private Object originalContext;
       
  +    /** Holds value of property ascending. */
  +    private boolean ascending = true;    
       
       public ForEachTag() {
       }
  @@ -162,6 +164,7 @@
           xpath = null;
           sortXPath = null;
           distinct = false;
  +        ascending = true;
       }
   
       
  @@ -241,13 +244,31 @@
       }
       
       
  +    /** Getter for property ascending.
  +     * @return Value of property ascending.
  +     */
  +    public boolean isAscending() {
  +        return ascending;
  +    }
  +    
  +    /** Setter for property ascending.
  +     * @param ascending New value of property ascending.
  +     */
  +    public void setAscending(boolean ascending) {
  +        this.ascending = ascending;
  +    }
  +    
       // Implementation methods
       //-------------------------------------------------------------------------                    
       protected List selectNodes() {
           if ( xpath != null ) {    
               Object input = getInputNodes();
               if ( sortXPath != null ) {
  -                return xpath.selectNodes( input, sortXPath, distinct );
  +                List answer = xpath.selectNodes( input, sortXPath, distinct );
  +                if ( ! ascending ) {
  +                    Collections.reverse( answer );
  +                }
  +                return answer;
               }
               else {
                   return xpath.selectNodes( input );
  
  
  
  1.17      +15 -0     jakarta-taglibs/xtags/xml/xtags.xml
  
  Index: xtags.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-taglibs/xtags/xml/xtags.xml,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- xtags.xml	26 Nov 2001 17:50:38 -0000	1.16
  +++ xtags.xml	18 Jan 2002 18:44:02 -0000	1.17
  @@ -712,6 +712,15 @@
         </description>
       </attribute>
       <attribute>
  +      <name>ascending</name>
  +      <required>false</required>
  +      <rtexprvalue>true</rtexprvalue>
  +      <description>
  +        This boolean attribute defaults to true. If set to false then
  +        the sort is made in descending order.
  +      </description>
  +    </attribute>
  +    <attribute>
         <name>context</name>
         <required>false</required>
         <rtexprvalue>true</rtexprvalue>
  @@ -1380,6 +1389,12 @@
   
     </tagtoc>
   </taglib>
  +
  +<revision release="Patches" date="01/20/2002">
  +  <description>
  +    Added new boolean attribute 'ascending' on &lt;xtags:forEach&gt; which allows sorting in ascending or descending order.
  +  </description>
  +</revision>
   
   <revision release="Patches" date="11/26/2001">
     <description>
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>