Juliana Arnolds --

If I use a paginated list, I can sort information prior to getting to the JSP; the displaytag api doesn't do the sorting for me. By the way, do the "Item" objects override the equals() and hashCode() methods? (They are necessary if you wish to sort a list.)

Attached is my implementation of a paginated list.

-- Sean

On 05/31/2010 08:46 PM, Juliana Arnolds wrote:
Hi,
I'm having trouble performing an external sort. I have a paginated list containing a list of "Item" objects. Each "Item" object contains an object, "InnerTestClass" as shown below. The InnerTestClass contains 2 member variables, testId and testName. I need to be able to perform a sort on the testId and testName attributes of the encapsulated class, InnerTestClass. Is this possible?

public class Item {
// other member variables with getter and setters
    private class InnerTestClass innerClass;
    public void setInnerClass(InnerTestClass innerClass) {
        this.innerClass = innerClass;
    }
    public InnerTestClass getInnerClass() {
        return innerClass;
    }
}

I can set the default sort as "testId" and the table will render because when it first displays the sort is null. However, if I click on the column entitled, "Item Name", then the query string has "sort=innerClass.testName" when I need it to be "sort=testName". Is there anyway to set this explicitly or is display tag just using the property name that is set?


<display:table name="items" uid="foo" requestURI="display.spr" sort="external" partialList="true" size="${items.fullListSize}" pagesize="4"> <display:column property="innerClass.testId" title="Item Uid" sortName="testId">
        ${foo.innerClass.testId}&nbsp;
</display:column>
<display:column property="innerClass.testName" title="Item Name" sortName="testName" sortable="true" headerClass="sortable">
        ${foo.innerClass.testName}&nbsp;
</display:column>
</display:table>

Any help would be greatly appreciated --
Thanks!
J


------------------------------------------------------------------------------


_______________________________________________
displaytag-user mailing list
displaytag-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/displaytag-user

package utils;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.displaytag.pagination.PaginatedList;
import org.displaytag.properties.SortOrderEnum;

public class PaginatedListImpl implements PaginatedList {
        private static int DEFAULT_PAGE_SIZE = 10;
        private int fullListSize;
        private List<?> list;
        private int index;
        private int objectsPerPage;
        private int pageNumber;
        private String searchId;
        private String sortCriterion;
        private SortOrderEnum sortDirection;
        
        public PaginatedListImpl() {}
        
        public PaginatedListImpl(int fullListSize, List<?> list, int 
objectsPerPage, 
                                                                                
                         int pageNumber, String searchId,
                                                                                
                         String sortCriterion, SortOrderEnum sortDirection ) {
                super();
                this.fullListSize = fullListSize;
                this.list = list;
                this.objectsPerPage = objectsPerPage;
                this.pageNumber = pageNumber;
                this.searchId = searchId;
                this.sortCriterion = sortCriterion;
                this.sortDirection = sortDirection;
        }

        public PaginatedListImpl( HttpServletRequest request ) {
                sortCriterion = request.getParameter("sort");
                sortDirection = "desc".equals(request.getParameter("dir"))? 
SortOrderEnum.DESCENDING : SortOrderEnum.ASCENDING;
                objectsPerPage = DEFAULT_PAGE_SIZE;
                String page = request.getParameter( "page" );
                index = page == null ? 0 : Integer.parseInt( page ) - 1;
        }

        public int getFullListSize() {
                return fullListSize;
        }

        public void setFullListSize(int fullListSize) {
                this.fullListSize = fullListSize;
        }

        public List<?> getList() {
                return list;
        }

        public void setList(List<?> list) {
                this.list = list;
        }

        public int getObjectsPerPage() {
                return objectsPerPage;
        }

        public void setObjectsPerPage(int objectsPerPage) {
                this.objectsPerPage = objectsPerPage;
        }

        public int getPageNumber() {
                return pageNumber;
        }
        
        public int getIndex() {
                return 1 + (( pageNumber - 1 ) * 10 );
        }

        public void setPageNumber(int pageNumber) {
                this.pageNumber = pageNumber;
        }

        public String getSearchId() {
                return searchId;
        }

        public void setSearchId(String searchId) {
                this.searchId = searchId;
        }

        public String getSortCriterion() {
                return sortCriterion;
        }

        public void setSortCriterion(String sortCriterion) {
                this.sortCriterion = sortCriterion;
        }

        public SortOrderEnum getSortDirection() {
                return sortDirection;
        }

        public void setSortDirection(SortOrderEnum sortDirection) {
                this.sortDirection = sortDirection;
        }
}
------------------------------------------------------------------------------

_______________________________________________
displaytag-user mailing list
displaytag-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/displaytag-user

Reply via email to