org.apache.commons.scaffold.util
Class Scroller

java.lang.Object
  extended by org.apache.commons.scaffold.util.Scroller

public class Scroller
extends Object

Scroller tracks the coordinates needed to manage flipping through a result list using LIMIT and OFFSET clauses (or the equivalent). Scrolls through entries using a range (10 to 20 of 50) but does not support paging per se goto page 3 (or entry 30)), though that would be an easy enhancement.

Version:
$Revision: 155464 $ $Date: 2005-02-26 13:26:54 +0000 (Sat, 26 Feb 2005) $
Author:
James Klicman , Ted Husted, WXXI Public Broadcasting Council, OK State DEQ

Field Summary
protected  int count
          The maximum number of entries available (the SQL count).
protected  int entries
          The actual number of entries to fetch (eg length or limit).
protected  int from
          The starting point for the current query [FROM].
static int FROM
          The default starting point [1].
protected  int limit
          The maximum number of entries to fetch at a time [Integer.MAX_VALUE].
protected  int next
          The starting point to use with a "forward" query.
protected  Map parameters
          Field for the parameters property [java.util.HashMap].
protected  int prev
          The starting point to use for a "backward" query.
static int SCROLL_ROWS
          The maximum to return with a scrolling list.
protected  int thru
          The ending point for the current query [1].
 
Constructor Summary
Scroller()
           
Scroller(int entries, int from, int limit, int count)
           
 
Method Summary
 void calculate()
          Calculate the new property values using a bean that has already had count and limit set.
 void calculate(int entries)
          Calculate the new property values using a bean that has already had count and limit set.
 void calculate(int entries, int from, int count, int limit)
          Calculate the new property values.
 int getCount()
          Return count.
 int getEntries()
          Return entries.
 int getFrom()
          Return from.
 String getHiddenFields()
          Return parameters as a series of hidden HTML fields.
 int getLimit()
          Return limit.
 int getNext()
          Return next.
 int getOffset()
          The database offset for the current query [0].
 int getOffsetForPage(int page)
          Return first entry for given page.
 int getPage()
          Return current page number
 int getPage(int thru)
          Return page number for given entry.
 int getPages()
          Return number of pages.
 Map getParameters()
          Return parameters.
 int getPrev()
          Return prev.
 String getQueryString(String uri)
          Return parameters as a query string for use with a URI.
 int getThru()
          Return thru.
 boolean isParameters()
          Set a parameter
 void putParameter(String key, String value)
          Set a parameter
 void setCount(int count)
          Set count
 void setEntries(int entries)
          Set entries
 void setFrom(int from)
          Set from.
 void setLimit(int limit)
          Set limit.
 void setNext(int next)
          Set next.
 void setParameters(Map parameters)
          Set parameters
 void setPrev(int prev)
          Set prev.
 void setThru(int thru)
          Set thru.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SCROLL_ROWS

public static final int SCROLL_ROWS
The maximum to return with a scrolling list.

See Also:
Constant Field Values

FROM

public static int FROM
The default starting point [1]. The value is for the convenience of SQL, which is one-based.


from

protected int from
The starting point for the current query [FROM].


thru

protected int thru
The ending point for the current query [1].


prev

protected int prev
The starting point to use for a "backward" query.


next

protected int next
The starting point to use with a "forward" query. This should always be a valid value.


limit

protected int limit
The maximum number of entries to fetch at a time [Integer.MAX_VALUE].


entries

protected int entries
The actual number of entries to fetch (eg length or limit).


count

protected int count
The maximum number of entries available (the SQL count).


parameters

protected Map parameters
Field for the parameters property [java.util.HashMap].

Constructor Detail

Scroller

public Scroller(int entries,
                int from,
                int limit,
                int count)

Scroller

public Scroller()
Method Detail

setFrom

public void setFrom(int from)
Set from.

Parameters:
from - The new from value.

getFrom

public int getFrom()
Return from.

Returns:
The form value.

setThru

public void setThru(int thru)
Set thru.

Parameters:
thru - The new thru value.

getThru

public int getThru()
Return thru.

Returns:
The form value.

setPrev

public void setPrev(int prev)
Set prev.

Parameters:
prev - The new prev value.

getPrev

public int getPrev()
Return prev.

Returns:
The prev value.

setNext

public void setNext(int next)
Set next.

Parameters:
next - The new next value.

getNext

public int getNext()
Return next.

Returns:
The next value.

setLimit

public void setLimit(int limit)
Set limit.

Parameters:
limit - The new limit value.

getLimit

public int getLimit()
Return limit.

Returns:
The limit value.

setEntries

public void setEntries(int entries)
Set entries

Parameters:
entries - The new entries value.

getEntries

public int getEntries()
Return entries.

Returns:
The entries value.

setCount

public void setCount(int count)
Set count

Parameters:
count - The new count value.

getCount

public int getCount()
Return count.

Returns:
The count value.

setParameters

public void setParameters(Map parameters)
Set parameters

Parameters:
parameters - The new parameters value.

getParameters

public Map getParameters()
Return parameters.

Returns:
The parameters value.

putParameter

public void putParameter(String key,
                         String value)
Set a parameter

Parameters:
key - The parameter name
value - The parameter value

isParameters

public boolean isParameters()
Set a parameter

Parameters:
key - The parameter name
value - The parameter value

getQueryString

public String getQueryString(String uri)
Return parameters as a query string for use with a URI.

Returns:
query string

getHiddenFields

public String getHiddenFields()
Return parameters as a series of hidden HTML fields.

Returns:
parameters as a series of hidden HTML fields.

getOffset

public int getOffset()
The database offset for the current query [0]. Convenience method to return one less than from

Returns:
The offset for this query

getPage

public int getPage(int thru)
Return page number for given entry.

Returns:
The number of pages

getPage

public int getPage()
Return current page number

Returns:
The number of pages

getPages

public int getPages()
Return number of pages.

Returns:
The number of pages

getOffsetForPage

public int getOffsetForPage(int page)
Return first entry for given page.

Returns:
first entry for given page

calculate

public void calculate()
Calculate the new property values using a bean that has already had count and limit set.

Parameters:
from - The first absolute row

calculate

public void calculate(int entries)
Calculate the new property values using a bean that has already had count and limit set.

Parameters:
from - The first absolute row

calculate

public void calculate(int entries,
                      int from,
                      int count,
                      int limit)
Calculate the new property values.

Parameters:
entries - The number of matches in this set
from - The first absolute row in this set
count - How many rows in the complete set
limit - The maximum rows in a subset page


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.