Velocity Tools
  1. Velocity Tools
  2. VELTOOLS-85

DESCENDING order is not preserved in SortTool

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2, 1.3
    • Fix Version/s: 1.4, 2.x
    • Component/s: GenericTools
    • Labels:
      None
    • Environment:
      jdk1.5, jboss4.0.4, struts1.3.8, velocity-tools1.3

      Description

      I have a property list for each page in my application that I store in the session. If the user sorts the column in DESCENDING order I add 'desc' to the property name and pass that list to the SortTool. The problem is that in the PropertiesComparator constructor, my list gets assigned to the member field and the member field is changed (the ':desc' is removed from the list). The result is the next time the user returns to the page with the column in DESCENDING order, the order is ASCENDING, which is not what I want. I want to preserve the user's selection.

      Here is the code in SortTool I'm referring to:

      public class PropertiesComparator implements Comparator
      {
      ...
      List properties;
      ...
      public PropertiesComparator(List properties)
      {
      this.properties = properties; //the member list is pointing to my list now
      ...
      int colonIndex = prop.indexOf(':');
      if (colonIndex != -1)
      {
      String sortType = prop.substring(colonIndex + 1);
      properties.set(i, prop.substring(0, colonIndex)); //and here the 'desc' is removed

      I rebuild the velocity-tools.jar with the following changes to fix the problem:

      public PropertiesComparator(List propertiesList)
      {
      // I am copying my properties list to the member list instead of pointing to the same list

      properties = new ArrayList(propertiesList.size());
      properties.addAll(propertiesList);

        Activity

        Hide
        Nathan Bubna added a comment -

        Fixed in both 1.x and 2.x. Thanks!

        Show
        Nathan Bubna added a comment - Fixed in both 1.x and 2.x. Thanks!

          People

          • Assignee:
            Nathan Bubna
            Reporter:
            Tatyana
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development