|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.hd.d.pg2k.webSvr.catalogue.PaginationBeanBase
org.hd.d.pg2k.webSvr.catalogue.PaginationBeanNumeric
public final class PaginationBeanNumeric
Bean to help with the pagination for otherwise large pages; this generates numeric labels. This can parse an input argument indicating the desired page, or find it directly in an incoming HttpRequest, and work out which page is meant and return it as an int for the page logic to use.
This can also generate the labels/values for one or more HTML form submit buttons to help generate the HTML page.
This implementation generates sequential page-numbering for buttons in its simplest form, but if there are too many buttons to show this then generates a sparser set that ensures that a user can navigate in few clicks to any page and especially so to nearby pages as they home in on a target.
This class is designed to be extended by classes that can put arbitraty labels on the buttons, for example words to help the user go directly to the desired page.
If given an unparseable page number as input, this and deriving implementations should always return a valid page number, returning the "safe" page number of 1 if they cannot deduce the correct page or a near one.
This bases its pagination on the properties in WebConsts dictating the maximum number of items to show on a page and the maximum number of page-choice buttons to show to a user.
This needs to be told the number of entries to be paginated; deriving classes may accept other or extra information in lieu.
This does its basic pagination based on the number of items to be paginated and the WebConsts that dictate maximum items per page and maximum pages or choices of pages to go to at once. In principle these might be user-settable rather than constants.
This is designed to be used as a bean at page or request scope in a JSP, though may be usable outside that environment. It may not be usefully serialisable.
THIS CLASS IS NOT THREAD SAFE since its usual enviroment and indeed lifetime is within the thread of a single servlet/JSP page service and thread-safety is an unnecessary overhead. Its methods are not synchronized, and if it is necessary to share one instance between threads they must hold a lock on the instance.
| Field Summary | |
|---|---|
private static java.util.List<java.lang.String> |
pageLabels1Upwards
Immutable List of String labels containing decimal integers from 1 to WebConsts.MAX_RESULTS_PAGES. |
private static long |
serialVersionUID
Unique Serialisation class ID generated by http://random.hd.org/. |
| Constructor Summary | |
|---|---|
PaginationBeanNumeric()
|
|
| Method Summary | |
|---|---|
private static java.util.List<java.lang.String> |
generateNewNumericPageLabels1Upwards(int nPages)
Generate a new immutable List of pageLabels from "1" upwards each time; argument must be non-negative. |
private static java.util.List<java.lang.String> |
generateNumericPageLabels1Upwards(int nPages)
Return an immutable List of contigious String (int-valued) labels for page buttons from 1 upwards. |
java.lang.String |
getPageLabel(int pageNum)
Return the page label for the given page (1 upwards), never null; the page must be in range else the result is undefined. |
java.util.List<java.lang.String> |
getPageLabels()
Gets ordered (unmodifiable) List of String labels/tokens for page buttons. |
int |
getPageNumber(java.lang.String s)
Get the page number as a from the String label; in case of bad input return 1. |
| Methods inherited from class org.hd.d.pg2k.webSvr.catalogue.PaginationBeanBase |
|---|
getEndIndex, getNumberOfItems, getNumberOfPages, getPageNumbers, getPg, getStartIndex, setNumberOfItems, setPg, setPg |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final java.util.List<java.lang.String> pageLabels1Upwards
Used to cover the most common cases without needing to generate lots of new objects each time.
private static final long serialVersionUID
| Constructor Detail |
|---|
public PaginationBeanNumeric()
| Method Detail |
|---|
public int getPageNumber(java.lang.String s)
A deriving class may override this for more sophisticated or specialised parses.
getPageNumber in class PaginationBeanBasepublic java.util.List<java.lang.String> getPageLabels()
Computes a set of pages and returns String values to use as the values (and legends) for submit buttons for this class to parse with the setPg(String) routine.
These labels have to be accepted by setPg(String).
The labels are unique and identify pages in monotonically-increasing order as you iterate through the List.
The labels generated must be deterministic and depend only on the attributes set for the bean.
Usually the first and last items in the List a labels for the first and last pages in the range.
Usually labels for the current page and those immediately before and after it are in the result list.
The base implementation returns numeric labels, but this calls getPageLabel() to generate the individual labels, so it may often be sufficient to override getPageLabel() only in a derived class.
This will commonly be overridden in deriving classes but the general contract must be maintained.
getPageLabels in class PaginationBeanBasepublic java.lang.String getPageLabel(int pageNum)
The label generated must be deterministic and depend only on the attributes set for the bean, and the same as getPageLabels() would have generated for this given page.
getPageLabel in class PaginationBeanBaseprivate static java.util.List<java.lang.String> generateNumericPageLabels1Upwards(int nPages)
nPages - requests list of String labels for buttons for the decimal integers
from "1" upwards so a value of 3 would return the list "1", "2", "3" for example;
the argument must be non-negativeprivate static final java.util.List<java.lang.String> generateNewNumericPageLabels1Upwards(int nPages)
|
DHD Multimedia Gallery V1.57.21 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||