The following forum message was posted by  at 
http://sourceforge.net/projects/displaytag/forums/forum/249318/topic/3802012:

Hi!

I have a problem sorting decorated values in a displayTag column.  Here is the 
description of the \"sortProperty\" attribute of a column:
name of the property in the bean specified in the parent table tag 
 (via the \"name\" attribute) which will be used to sort values in the 
 column. This can be used when the column body is filled or a 
 decorator is used and column should sort on undecorated values.

The last line suggests that if the attribute is not set, the decorated values 
will be used for the sort.  This does not work for me.  Basically, I receive a 
collection with an ID.  The ID refers to a description that is not present in 
the collection itself.  The descriptions are stored in an application object.  
Through the use of a DisplayTagColumnDecorator, with the ID, the description is 
retrieved and displayed correctly in the column.  The problem is when the 
column is sorted, the ID is used to do the sorting and not the \"decorated\" 
content of the column.  Am I missing something or did I interpret the attribute 
description incorrectly?  How can I make it so that the \"decorated\" 
description is used  for sorting instead of the ID?

Here is an example to reproduce the problem.  Instead of an application object, 
I just return names from a static list in the decorator.

decorator.jsp:
[code]<%@ page contentType=\"text/html; charset=UTF-8\"%>
<%@ taglib prefix=\"s\" uri=\"/struts-tags\"%>
<%@ taglib uri=\"http://displaytag.sf.net\"; prefix=\"display\"%>

<html>
<head>
<title>Decorator test</title>
</head>
<body>
        <s:set var=\"myList\" value=\"taskList\" scope=\"request\" />
        <display:table name=\"myList\" uid=\"row\" requestURI=\"\">
                <display:column property=\"id\" sortable=\"true\" />
                <display:column property=\"taskName\" sortable=\"true\" />
                <display:column property=\"id\" sortable=\"true\" 
title=\"Decorator\"
                        decorator=\"fou.fouDecorator\"/>
        </display:table>
</body>[/code]

Task.java:
[code]package fou;

public class Task {
        private Integer id;
        private String taskName;
        private Double amount;

        public Task() {
        }
        
        public String getTaskName() {
                return taskName;
        }
        public void setTaskName(String taskName) {
                this.taskName = taskName;
        }
        public Double getAmount() {
                return amount;
        }
        public void setAmount(Double amount) {
                this.amount = amount;
        }
        public void setId(Integer id) {
                this.id = id;
        }
        public Integer getId() {
                return id;
        }
}[/code]

actionDecorator.java:
[code]package fou;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

public class actionDecorator extends ActionSupport {

        private static final long serialVersionUID = 1L;
        List<Task> taskList = new ArrayList<Task>();

        public String execute() {
                
                taskList = new ArrayList<Task>();
                for (int i = 0; i < 10; ++i) {
                        Task t = new Task();
                        t.setId(i);
                        t.setTaskName(\"Task \" + i);
                        taskList.add(t);        
                }
                return SUCCESS;
        }

        public List<Task> getTaskList() {
                return taskList;
        }

        public void setTaskList(List<Task> taskList) {
                this.taskList = taskList;
        }

}[/code]

fouDecorator.java:
[code]package fou;

import javax.servlet.jsp.PageContext;

import org.displaytag.decorator.DisplaytagColumnDecorator;
import org.displaytag.exception.DecoratorException;
import org.displaytag.properties.MediaTypeEnum;

public class fouDecorator implements DisplaytagColumnDecorator {
        private static final String[] players = { \"Roger\", \"Rafa\", 
\"Novak\", \"Andy\",
                        \"Robin\", \"Nikolay\", \"Tomas\", \"Juan\", 
\"Fernando\", \"Jo-Wilfred\" };

        @Override
        public Object decorate(Object arg0, PageContext arg1, MediaTypeEnum 
arg2)
                        throws DecoratorException {
                return players[(Integer)arg0];
        }

}[/code]

Struts2 (struts.xml):
[code]
...
<action name=\"goDecorator\" method=\"execute\" class=\"fou.actionDecorator\">
  <result name=\"success\">/jsp/decorator.jsp</result>
</action>
[/code]

When the decorator column is clicked to sort, the ID is used instead of the 
names ...

Thanks for your help!

Fred.
foui...@yahoo.com

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
displaytag-user mailing list
displaytag-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/displaytag-user

Reply via email to