The following comment has been added to this issue: Author: Ludovic BERT Created: Tue, 9 Nov 2004 4:35 PM Body: Instead of displaying numbers for the page links (1,2,3), is better to display the value of the sorted column for the first row of the next page? This way the links act as an index to the user, and become extremely more useful. I have exactly the same need for an application using displaytag, so I have developed the patch, httpunit test and documentation update on this issue.
The complete patch file can be view below: Index: src/java/org/displaytag/pagination/NumberedPage.java =================================================================== RCS file: /cvsroot/displaytag/displaytag/src/java/org/displaytag/pagination/NumberedPage.java,v retrieving revision 1.10 diff -u -r1.10 NumberedPage.java --- src/java/org/displaytag/pagination/NumberedPage.java 26 Oct 2004 18:37:25 -0000 1.10 +++ src/java/org/displaytag/pagination/NumberedPage.java 9 Nov 2004 21:20:13 -0000 @@ -21,16 +21,23 @@ * is the page selected? */ private boolean selected; + + /** + * property value. + */ + private String propValue; /** * Creates a new page with the specified number. * @param pageNumber page number * @param isSelected is the page selected? + * @param propValue the sorted property value */ - public NumberedPage(int pageNumber, boolean isSelected) + public NumberedPage(int pageNumber, boolean isSelected, String propValue) { this.number = pageNumber; this.selected = isSelected; + this.propValue = propValue; } /** @@ -50,6 +57,15 @@ { return this.selected; } + + /** + * Returns the sorted property value. + * @return the sorted property value + */ + public String getPropValue() + { + return this.propValue; + } /** * @see java.lang.Object#toString() @@ -59,6 +75,7 @@ return new ToStringBuilder(this, ShortToStringStyle.SHORT_STYLE) // .append("selected", this.selected) //$NON-NLS-1$ .append("number", this.number) //$NON-NLS-1$ + .append("propValue", this.propValue) //$NON-NLS-1$ .toString(); } } \ No newline at end of file Index: src/java/org/displaytag/pagination/Pagination.java =================================================================== RCS file: /cvsroot/displaytag/displaytag/src/java/org/displaytag/pagination/Pagination.java,v retrieving revision 1.13 diff -u -r1.13 Pagination.java --- src/java/org/displaytag/pagination/Pagination.java 24 Oct 2004 13:55:48 -0000 1.13 +++ src/java/org/displaytag/pagination/Pagination.java 9 Nov 2004 21:20:13 -0000 @@ -81,14 +81,15 @@ * Adds a page. * @param number int page number * @param isSelected is the page selected? + * @param propValue the sorted property value */ - public void addPage(int number, boolean isSelected) + public void addPage(int number, boolean isSelected, String propValue) { if (log.isDebugEnabled()) { log.debug("adding page " + number); } - this.pages.add(new NumberedPage(number, isSelected)); + this.pages.add(new NumberedPage(number, isSelected, propValue)); } /** @@ -226,7 +227,7 @@ String urlString = ((Href) this.href.clone()).addParameter(this.pageParam, pageNumber).toString(); // needed for MessageFormat : page number/url - Object[] pageObjects = {pageNumber, urlString}; + Object[] pageObjects = {pageNumber, urlString, page.getPropValue()}; // selected page need a different formatter if (page.getSelected()) Index: src/java/org/displaytag/pagination/SmartListHelper.java =================================================================== RCS file: /cvsroot/displaytag/displaytag/src/java/org/displaytag/pagination/SmartListHelper.java,v retrieving revision 1.15 diff -u -r1.15 SmartListHelper.java --- src/java/org/displaytag/pagination/SmartListHelper.java 24 Oct 2004 13:55:43 -0000 1.15 +++ src/java/org/displaytag/pagination/SmartListHelper.java 9 Nov 2004 21:20:13 -0000 @@ -7,8 +7,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.displaytag.Messages; +import org.displaytag.model.Row; +import org.displaytag.model.TableModel; import org.displaytag.properties.TableProperties; import org.displaytag.util.Href; +import org.displaytag.util.LookupUtil; import org.displaytag.util.ShortToStringStyle; @@ -32,12 +35,17 @@ private static Log log = LogFactory.getLog(SmartListHelper.class); /** + * table model. + */ + private TableModel tableModel; + + /** * full list. */ private List fullList; /** - * sixe of the full list. + * size of the full list. */ private int fullListSize; @@ -64,12 +72,13 @@ /** * Creates a SmarListHelper instance that will help you chop up a list into bite size pieces that are suitable for * display. + * @param tableModel table model * @param list List * @param fullSize size of the full list * @param itemsInPage number of items in a page (int > 0) * @param tableProperties TableProperties */ - public SmartListHelper(List list, int fullSize, int itemsInPage, TableProperties tableProperties) + public SmartListHelper(TableModel tableModel, List list, int fullSize, int itemsInPage, TableProperties tableProperties) { if (log.isDebugEnabled()) { @@ -77,6 +86,7 @@ new Object[]{new Integer(list.size()), new Integer(itemsInPage), new Integer(fullSize)})); } + this.tableModel = tableModel; this.properties = tableProperties; this.pageSize = itemsInPage; this.fullList = list; @@ -270,10 +280,10 @@ // if no items are found still add pagination? if (count == 0) { - pagination.addPage(1, true); + pagination.addPage(1, true, ""); } - if (currentIndex < maxPages) + if (currentIndex <= maxPages / 2) { startPage = 1; endPage = maxPages; @@ -284,7 +294,7 @@ } else { - startPage = currentIndex; + startPage = currentIndex - maxPages / 2; while (startPage + maxPages > (count + 1)) { startPage--; @@ -299,13 +309,26 @@ pagination.setPrevious(new Integer(currentIndex - 1)); } + Object propValue = null; for (int j = startPage; j <= endPage; j++) { - if (log.isDebugEnabled()) + try + { + propValue = ""; + if (this.tableModel.getSortedColumnNumber() != -1) + { + propValue = LookupUtil.getBeanProperty(((Row) fullList.get(getFirstIndexForPage(j))).getObject(), this.tableModel.getSortedColumnHeader().getBeanPropertyName()); + } + if (log.isDebugEnabled()) + { + log.debug("adding page " + j); //$NON-NLS-1$ + } + } + catch (Exception e) { - log.debug("adding page " + j); //$NON-NLS-1$ + // Nothing to do } - pagination.addPage(j, (j == currentIndex)); + pagination.addPage(j, (j == currentIndex), propValue.toString()); } if (currentIndex != count) Index: src/java/org/displaytag/properties/TableTag.properties =================================================================== RCS file: /cvsroot/displaytag/displaytag/src/java/org/displaytag/properties/TableTag.properties,v retrieving revision 1.15 diff -u -r1.15 TableTag.properties --- src/java/org/displaytag/properties/TableTag.properties 9 Oct 2004 09:59:08 -0000 1.15 +++ src/java/org/displaytag/properties/TableTag.properties 9 Nov 2004 21:20:13 -0000 @@ -78,7 +78,7 @@ paging.banner.onepage=<span class="pagelinks">{0}</span> paging.banner.page.selected=<strong>{0}</strong> -paging.banner.page.link=<a href="{1}" title="Go to page {0}">{0}</a> +paging.banner.page.link=<a href="{1}" title="Go to page {0} : ({2})">{0}</a> paging.banner.page.separator=, # unused Index: src/java/org/displaytag/tags/TableTag.java =================================================================== RCS file: /cvsroot/displaytag/displaytag/src/java/org/displaytag/tags/TableTag.java,v retrieving revision 1.89 diff -u -r1.89 TableTag.java --- src/java/org/displaytag/tags/TableTag.java 4 Nov 2004 23:35:46 -0000 1.89 +++ src/java/org/displaytag/tags/TableTag.java 9 Nov 2004 21:20:14 -0000 @@ -1289,7 +1289,7 @@ // SmartListHelper to figure out what page they are after, etc... if (this.pagesize > 0) { - this.listHelper = new SmartListHelper(fullList, fullList.size(), this.pagesize, this.properties); + this.listHelper = new SmartListHelper(this.tableModel, fullList, fullList.size(), this.pagesize, this.properties); this.listHelper.setCurrentPage(this.pageNumber); pageOffset = this.listHelper.getFirstIndexForCurrentPage(); fullList = this.listHelper.getListForCurrentPage(); Index: src/test/org/displaytag/util/ToStringTest.java =================================================================== RCS file: /cvsroot/displaytag/displaytag/src/test/org/displaytag/util/ToStringTest.java,v retrieving revision 1.1 diff -u -r1.1 ToStringTest.java --- src/test/org/displaytag/util/ToStringTest.java 19 Oct 2004 18:28:05 -0000 1.1 +++ src/test/org/displaytag/util/ToStringTest.java 9 Nov 2004 21:20:14 -0000 @@ -42,7 +42,7 @@ */ public void testSmartListHelper() { - checkToString(new SmartListHelper(new ArrayList(), 100, 10, TableProperties.getInstance(null))); + checkToString(new SmartListHelper(new TableModel(null, null), new ArrayList(), 100, 10, TableProperties.getInstance(null))); } /** @@ -50,7 +50,7 @@ */ public void testNumberedPage() { - checkToString(new NumberedPage(1, false)); + checkToString(new NumberedPage(1, false, null)); } /** Index: xdocs/configuration.xml =================================================================== RCS file: /cvsroot/displaytag/displaytag/xdocs/configuration.xml,v retrieving revision 1.18 diff -u -r1.18 configuration.xml --- xdocs/configuration.xml 8 Nov 2004 02:33:03 -0000 1.18 +++ xdocs/configuration.xml 9 Nov 2004 21:20:15 -0000 @@ -158,7 +158,7 @@ <td>yes/yes</td> </tr> <tr> - <td>paging.banner. no_items_found</td> + <td>paging.banner.no_items_found</td> <td class="source"><span class="pagebanner"> No {0} found. </span></td> <td>Any string in a message format with 1 placeholder</td> <td> @@ -169,7 +169,7 @@ <td>yes/yes</td> </tr> <tr> - <td>paging.banner. one_item_found</td> + <td>paging.banner.one_item_found</td> <td class="source"><span class="pagebanner"> One {0} found. </span></td> <td>Any string in a message format with 1 placeholder</td> <td> @@ -180,7 +180,7 @@ <td>yes/yes</td> </tr> <tr> - <td>paging.banner. all_items_found</td> + <td>paging.banner.all_items_found</td> <td class="source"> <span class="pagebanner"> {0} {1} found, displaying all {2}. </span> </td> @@ -193,7 +193,7 @@ <td>yes/yes</td> </tr> <tr> - <td>paging.banner. some_items_found</td> + <td>paging.banner.some_items_found</td> <td class="source"> <span class="pagebanner"> {0} {1} found, displaying {2} to {3}. </span> </td> @@ -285,17 +285,17 @@ <td>yes/yes</td> </tr> <tr> - <td>paging.banner. page.selected</td> + <td>paging.banner.page.selected</td> <td class="source"><strong>{0}</strong></td> <td /> - <td>selected page. {0} is replaced with the page number, {1} with the page url.</td> + <td>selected page. {0} is replaced with the page number, {1} with the page url, {2} with the value of the first item of the sorted column or "" if there are no sorted column.</td> <td>yes/yes</td> </tr> <tr> - <td>paging.banner. page.link</td> - <td class="source"><a href="{1}" title="Go to page {0}">{0}</a></td> + <td>paging.banner.page.link</td> + <td class="source"><a href="{1}" title="Go to page {0} : ({2})">{0}</a></td> <td /> - <td>link to a page. {0} is replaced with the page number, {1} with the page url.</td> + <td>link to a page. {0} is replaced with the page number, {1} with the page url, {2} with the value of the first item of the sorted column or "" if there are no sorted column.</td> <td>yes/yes</td> </tr> <tr> Index: src/test/org/displaytag/jsptests/Displ42Test.java =================================================================== RCS file: src/test/org/displaytag/jsptests/Displ42Test.java diff -N src/test/org/displaytag/jsptests/Displ42Test.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/test/org/displaytag/jsptests/Displ42Test.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,53 @@ +package org.displaytag.jsptests; + +import org.displaytag.test.DisplaytagCase; + +import com.meterware.httpunit.GetMethodWebRequest; +import com.meterware.httpunit.WebLink; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + + +/** + * Tests for DISPL-42 - Page results Alphabetically + * @author Ludovic BERT + * @version $Revision: 1.1 $ ($Author: lbert $) + */ +public class Displ42Test extends DisplaytagCase +{ + + /** + * Instantiates a new test case. + * @param name test name + */ + public Displ42Test(String name) + { + super(name); + } + + /** + * @see org.displaytag.test.DisplaytagCase#getJspName() + */ + public String getJspName() + { + return "DISPL-42.jsp"; + } + + /** + * Check addictional parameters in paging.banner.*. + * @param jspName jsp name, with full path + * @throws Exception any axception thrown during test. + */ + public void doTest(String jspName) throws Exception + { + WebRequest request = new GetMethodWebRequest(jspName); + WebResponse response; + + response = runner.getResponse(request); + WebLink[] links = response.getLinks(); + assertEquals("Expected a different title.", "Go to page 2 : (4)", links[0].getTitle()); + assertEquals("Expected a different title.", "Go to page 3 : (7)", links[1].getTitle()); + assertEquals("Expected a different title.", "Go to page 4 : (10)", links[2].getTitle()); + } + +} Index: src/test-resources/el/DISPL-42.jsp =================================================================== RCS file: src/test-resources/el/DISPL-42.jsp diff -N src/test-resources/el/DISPL-42.jsp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/test-resources/el/DISPL-42.jsp 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,28 @@ +<jsp:root version="1.2" xmlns:jsp="http://java.sun.com/JSP/Page" + xmlns:display="urn:jsptld:../../../src/tld/displaytag-el-12.tld"> + <jsp:text> <![CDATA[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ]]> </jsp:text> + <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> + <head> + <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /> + <title>Displaytag unit test</title> + </head> + <body> + <jsp:scriptlet> <![CDATA[ + java.util.List theList = new java.util.ArrayList(); + for (int i = 1; i <= 10; i++) { + theList.add(new org.displaytag.test.NumberedItem(i)); + } + request.setAttribute( "test", theList); + ]]> </jsp:scriptlet> + <display:table name="requestScope.test" id="table" pagesize="3" defaultsort="1"> + <display:column property="number" sortable="true"/> + <display:setProperty name="paging.banner.full"><jsp:text><span id="navbar" class="pagelinks">[<a href="{1}">First</a>/<a href="{2}">Prev</a>] {0} [<a href="{3}">Next</a>/<a href="{4}">Last</a>]</span></jsp:text></display:setProperty> + <display:setProperty name="paging.banner.first"><jsp:text><span id="navbar" class="pagelinks">[First/Prev] {0} [<a href="{3}">Next</a>/<a href="{4}">Last</a>]</span></jsp:text></display:setProperty> + <display:setProperty name="paging.banner.last"><jsp:text><span id="navbar" class="pagelinks">[<a href="{1}">First</a>/<a href="{2}">Prev</a>] {0} [Next/Last]</span></jsp:text></display:setProperty> + <display:setProperty name="paging.banner.onepage"><jsp:text><span id="navbar" class="pagelinks">{0}</span></jsp:text></display:setProperty> + <display:setProperty name="paging.banner.page.link"><jsp:text><a href="{1}" title="Go to page {0} : ({2})">{0}</a></jsp:text></display:setProperty> + </display:table> + </body> + </html> +</jsp:root> Index: src/test-resources/tld11/DISPL-42.jsp =================================================================== RCS file: src/test-resources/tld11/DISPL-42.jsp diff -N src/test-resources/tld11/DISPL-42.jsp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/test-resources/tld11/DISPL-42.jsp 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,28 @@ +<jsp:root version="1.2" xmlns:jsp="http://java.sun.com/JSP/Page" + xmlns:display="urn:jsptld:../../../src/tld/displaytag-12.tld"> + <jsp:text> <![CDATA[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> ]]> </jsp:text> + <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> + <head> + <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /> + <title>Displaytag unit test</title> + </head> + <body> + <jsp:scriptlet> <![CDATA[ + java.util.List theList = new java.util.ArrayList(); + for (int i = 1; i <= 10; i++) { + theList.add(new org.displaytag.test.NumberedItem(i)); + } + request.setAttribute( "test", theList); + ]]> </jsp:scriptlet> + <display:table name="requestScope.test" id="table" pagesize="3" defaultsort="1"> + <display:column property="number" sortable="true"/> + <display:setProperty name="paging.banner.full"><jsp:text><span id="navbar" class="pagelinks">[<a href="{1}">First</a>/<a href="{2}">Prev</a>] {0} [<a href="{3}">Next</a>/<a href="{4}">Last</a>]</span></jsp:text></display:setProperty> + <display:setProperty name="paging.banner.first"><jsp:text><span id="navbar" class="pagelinks">[First/Prev] {0} [<a href="{3}">Next</a>/<a href="{4}">Last</a>]</span></jsp:text></display:setProperty> + <display:setProperty name="paging.banner.last"><jsp:text><span id="navbar" class="pagelinks">[<a href="{1}">First</a>/<a href="{2}">Prev</a>] {0} [Next/Last]</span></jsp:text></display:setProperty> + <display:setProperty name="paging.banner.onepage"><jsp:text><span id="navbar" class="pagelinks">{0}</span></jsp:text></display:setProperty> + <display:setProperty name="paging.banner.page.link"><jsp:text><a href="{1}" title="Go to page {0} : ({2})">{0}</a></jsp:text></display:setProperty> + </display:table> + </body> + </html> +</jsp:root> --------------------------------------------------------------------- View this comment: http://jira.codehaus.org/browse/DISPL-42?page=comments#action_26259 --------------------------------------------------------------------- View the issue: http://jira.codehaus.org/browse/DISPL-42 Here is an overview of the issue: --------------------------------------------------------------------- Key: DISPL-42 Summary: Page results Alphabetically Type: Wish Status: Unassigned Priority: Minor Original Estimate: Unknown Time Spent: Unknown Remaining: Unknown Project: DisplayTag Components: Paging/Sorting Versions: 1.0 RC1 Assignee: Reporter: fabrizio giustina Created: Sat, 2 Oct 2004 11:54 AM Updated: Tue, 9 Nov 2004 4:35 PM Description: ==== imported from sf tracker id 760038 http://sourceforge.net/support/tracker.php?aid=760038 ==== I would like to be able to page through the results alphabetically. --------------------------------------------------------------------- JIRA INFORMATION: This message is automatically generated by JIRA. If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira ------------------------------------------------------- This SF.Net email is sponsored by: Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux. http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click _______________________________________________ displaytag-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/displaytag-devel