Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.2, 1.3
-
None
-
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);