org.mentawai.filter
Class PaginatorFilter

java.lang.Object
  extended by org.mentawai.filter.PaginatorFilter
All Implemented Interfaces:
Filter

public class PaginatorFilter
extends Object
implements Filter

This filter easily enables paging of data on top of your current structure. The data that should be paged must be placed in the output stack with the specified key (see constructor). Only arrays or Collections can be paged, other data will be silently ignored.

The data with the specified key will be replaced by an instance of the Paginator class which contains the paged data and some other useful information.

Let's say you want paged search results: Add this filter to the ActionConfig of your search action and don't forget to pass the page parameter to the query string:

http://example.com/search.mtw?q=keywords&p=0

The page parameter (which can be modified, see constructor) starts at 1. Use the other properties of the Paginator class to obtain information about the amount of all data, current page, maximum page and so on. With these information you can create links to the previous and next pages of your paged data.

Mentawai provides the PaginatorTag, but this filter can be more useful for Ajax requests or any other situation when you don't want or cannot use the PaginatorTag.

Author:
Sven Jacobs
See Also:
Paginator

Field Summary
static int DEFAULT_ITEMS_PER_PAGE
           
static String DEFAULT_PAGE_PARAM
           
 
Constructor Summary
PaginatorFilter(String key)
          Instantiate a PaginatorFilter with the specified key pointing to the data in the output stack which should be paged.
PaginatorFilter(String key, int itemsPerPage)
          Instantiate a PaginatorFilter with the specified key and amount of items per page.
PaginatorFilter(String key, int itemsPerPage, String pageParam)
          Instantiate a PaginatorFilter with the specified key, amount of items per page and name of the page parameter.
 
Method Summary
static Object[] copyOfRange(Object[] original, int from, int to)
           
 void destroy()
          Gives a chance to the filter to deallocalte any resources before it is destroyed.
 String filter(InvocationChain chain)
          The filter replaces the specified data with an instance of Paginator which contains the paged data and some other useful information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PAGE_PARAM

public static final String DEFAULT_PAGE_PARAM
See Also:
Constant Field Values

DEFAULT_ITEMS_PER_PAGE

public static final int DEFAULT_ITEMS_PER_PAGE
See Also:
Constant Field Values
Constructor Detail

PaginatorFilter

public PaginatorFilter(String key)
Instantiate a PaginatorFilter with the specified key pointing to the data in the output stack which should be paged.

Parameters:
key - Key of the data from the output stack to page

PaginatorFilter

public PaginatorFilter(String key,
                       int itemsPerPage)
Instantiate a PaginatorFilter with the specified key and amount of items per page.

Parameters:
key - Key of the data from the output stack to page
itemsPerPage - Amount of items per page

PaginatorFilter

public PaginatorFilter(String key,
                       int itemsPerPage,
                       String pageParam)
Instantiate a PaginatorFilter with the specified key, amount of items per page and name of the page parameter.

Parameters:
key - Key of the data from the output stack to page
itemsPerPage - Amount of items per page
pageParam - Name of the page parameter
Method Detail

filter

public String filter(InvocationChain chain)
              throws Exception
The filter replaces the specified data with an instance of Paginator which contains the paged data and some other useful information. Note: Only arrays and Collections can be paged.

Specified by:
filter in interface Filter
Parameters:
chain - The InvocationChain for the action this filter is being applied to.
Returns:
The result of the filter or the action the filter is being applied to.
Throws:
Exception
See Also:
Paginator

copyOfRange

public static Object[] copyOfRange(Object[] original,
                                   int from,
                                   int to)

destroy

public void destroy()
Description copied from interface: Filter
Gives a chance to the filter to deallocalte any resources before it is destroyed. This is called when the web application is stopped, in other words, this has nothing to do with garbage collection.

Specified by:
destroy in interface Filter


Copyright © 2013. All Rights Reserved.