SortFilterService Class

com.bea.wlw.netui.tags.databinding
SortFilterService Class

public final class SortFilterService

    extends Object

The SortFilterService is used to keep track of sorts and filters query parameters that are stored on the URL. These terms are used to create a DatabaseFilter which can be passed to a DatabaseControl to parameterize a SQL query.

The SortFilterService can be used as a storage location for parameters that need to be stored on the URL but may not be encoded in every anchor on every page in a Java Page Flow.

The SortFilterService is used to encode several bits of state for a specific grid onto the URL including:

This state should be specific to a given grid and is namespaced by the grid's name attribute. Multiple grids that may have parameters on the URL at the same time should have unique names.

In general, the methods on this class are used to manipulate the query parameters on URLs given the query parameters on the current request. Starting with the request's parameter map, additional parameters may be added or removed in order to build a map of values that can be attached to a given anchor or form that will render as the result of the current request. For example, a sort added to a column using the SortFilterService.getQueryParamsMapWithSort(String, String) could be available in an anchor that is rendered at the end of this request.


Hierarchy
Object
  SortFilterService

Field Summary

public static final String
PRIMARY_KEY
The request key for a row identifier.
public static final String
REQUEST_KEY
Key used to store a SortFilterSerivce object in the request.
public static final String
ROW_IDENTIFIER
The request key for a row identifier.
public static final int
SORT_ASCENDING
Constant representing an ascending sort applied to a column.
public static final int
SORT_DESCENDING
Constant representing a descending sort applied to a column.
public static final int
SORT_NONE
Constant representing no sorts applied to a column.
 

Method Summary

public void
addRowIdentifier(String gridName, String columnName, Object value)

Add a row identifier which is accessible using the SortFilterService.getRowIdQueryParamsMap() method.

public static String
decodeUniqueIdentifier(HttpServletRequest request, String gridName, String columnName)

Decode a value from the given request's query parameters.

public static String
encodeUniqueIdentifier(String gridName, String columnName, Object columnValue)

Encode a grid/column value constraint.

public int
getCurrentPage(String gridName)

Get the current page for a specific grid.

public DatabaseFilter
getDatabaseFilter(String gridName)

Gets a DatabaseFilter object that contains the sorts and filters on the current request's URL.

public static SortFilterService
getInstance(Object object)
Factory method to create a SortFilterService object.
public int
getPageSize()

Get the default page size.

public Map
getQueryParamsMap()

Get a Map of the query parameters that are on the current URL.

public Map
getQueryParamsMapWithPage(String gridName, int page)

Get a Map of query parameters that contains the request's parameters and a new parameter that sets the current page for the grid named gridName.

public Map
getQueryParamsMapWithSort(String gridName, String columnName)

Get a Map of query parameters that contains the request's parameters and a new parameter that sets a new sort on some column of a grid.

public Map
getRowIdQueryParamsMap()

Get the query params map that contains only the row identifiers that should be encoded on the URL.

public int
getSortDirection(String gridName, String columnName)

Get the sort direction of a column in a grid.

public boolean
isFiltered(String gridName, String columnName)

Check the filter state of a given column in a grid for the current request.

public boolean
isSorted(String gridName, String columnName)

Check the sort state of a given column in a grid for the current request.

public void
reset()

Clears all query information including the current page, sorts, and filters for all grid names that are on the URL.

public void
reset(String gridName)

Clears the current page, sorts, and filters for the grid named gridName.

public void
resetCurrentPage(String gridName)

Reset the current page of a specific grid.

public String
toString()

Utility method thath prints the current state of a SortFilterService instance.

public void
updateRowId(ServletRequest request)

Update the row identifiers given the current request.

 
Methods from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
   

Field Detail

PRIMARY_KEY

public static final String PRIMARY_KEY
The request key for a row identifier. This identifier is deprecated; use SortFilterService.ROW_IDENTIFIER instead.


REQUEST_KEY

public static final String REQUEST_KEY
Key used to store a SortFilterSerivce object in the request.


ROW_IDENTIFIER

public static final String ROW_IDENTIFIER
The request key for a row identifier.


SORT_ASCENDING

public static final int SORT_ASCENDING
Constant representing an ascending sort applied to a column.


SORT_DESCENDING

public static final int SORT_DESCENDING
Constant representing a descending sort applied to a column.


SORT_NONE

public static final int SORT_NONE
Constant representing no sorts applied to a column.

 

Method Detail

addRowIdentifier(String, String, Object) Method

public void addRowIdentifier(String gridName, 
                             String columnName, 
                             Object value)

Add a row identifier which is accessible using the SortFilterService.getRowIdQueryParamsMap() method. Row identifiers added for a particular grid name can be used in an Anchor or a Form to select a particular row to display on the next page.

Parameters

gridName
the name of the grid to which the row identifier is scoped
columnName
the name of the column that the identifier constrains
value
the value of the constraint on the row identifier.

decodeUniqueIdentifier(HttpServletRequest, String, String) Method

public static String decodeUniqueIdentifier(HttpServletRequest request, 
                                            String gridName, 
                                            String columnName)

Decode a value from the given request's query parameters. If the grid and column names are present in the row identifiers in the query parameters, this returns a String representation of the value's constraint.

Parameters

request
the request from which to find the unique identifier
gridName
the name of the grid whose unique identifiers to check
columnName
the name of the column whose constraint value to find

Returns

the String representation of a value to which the given column is constrained

encodeUniqueIdentifier(String, String, Object) Method

public static String encodeUniqueIdentifier(String gridName, 
                                            String columnName, 
                                            Object columnValue)

Encode a grid/column value constraint. This method formats the grid/column/value group into a syntax that can be used as the value of a query parameter on a URL.

Parameters

gridName
the grid name for the encoded identifier
columnName
the column name for the encoded identifer
columnValue
the value to encode

Returns

an encoded row identifier

getCurrentPage(String) Method

public int getCurrentPage(String gridName)

Get the current page for a specific grid.

Parameters

gridName
the name of a grid whose current page may appear in the current query parameters

Returns

if available, the current page; zero otherwise

getDatabaseFilter(String) Method

public DatabaseFilter getDatabaseFilter(String gridName)

Gets a DatabaseFilter object that contains the sorts and filters on the current request's URL.

The gridName is used to locate specific URL parameters that are associated with a particular Grid tag.

Parameters

gridName
the name of a grid on the page

Returns

a DatabaseFilter object that can be passed to a DatabaesControl instance to receive a sorted and filtered query result. Returns null if the gridName is null.

getInstance(Object) Method

public static SortFilterService getInstance(Object object)
Factory method to create a SortFilterService object. Usually, the object passed here is an HttpServletRequest.

Parameters

object
the object from which to create the SortFilterService, usually the HttpServletRequest

Returns

a SortFilterService for use during the current request.

getPageSize() Method

public int getPageSize()

Get the default page size.

Returns

the default size of a page, 10.

getQueryParamsMap() Method

public Map getQueryParamsMap()

Get a Map of the query parameters that are on the current URL. In general, this method is used to pass these parameters from page to page on an anchor or inside of a form.

Returns

a Map of the current query parameters

getQueryParamsMapWithPage(String, int) Method

public Map getQueryParamsMapWithPage(String gridName, 
                                     int page)

Get a Map of query parameters that contains the request's parameters and a new parameter that sets the current page for the grid named gridName.

If the grid specified here already has a current page query parameter, it is replaced with the new value.

Parameters

gridName
the name of the grid for which to set the current page
page
the page to display

Returns

a Map containing all of the current request's parameters and a new parameter that sets the page for the given grid.

getQueryParamsMapWithSort(String, String) Method

public Map getQueryParamsMapWithSort(String gridName, 
                                     String columnName)

Get a Map of query parameters that contains the request's parameters and a new parameter that sets a new sort on some column of a grid.

The criteria for creating a sort are these:

Parameters

gridName
the name of the grid for which to add a sort
columnName
the name of the column to sort

Returns

a Map containing all of the current request's parameters and a new parameter that sorts the grid on the given column.

getRowIdQueryParamsMap() Method

public Map getRowIdQueryParamsMap()

Get the query params map that contains only the row identifiers that should be encoded on the URL.

Returns

a Map that contains the query parameters which contain the row identifiers that uniquely represent a row in a data set.

getSortDirection(String, String) Method

public int getSortDirection(String gridName, 
                            String columnName)

Get the sort direction of a column in a grid. This method checks the current request's parameters and returns an identifier for the sort direction of the column.

Parameters

gridName
the name of the grid whose column to check
columnName
the name of the column

Returns

SortFilterService.SORT_ASCENDING if the column is sorted in ascending order, SortFilterService.SORT_DESCENDING if the column is sorted in descending order, and SortFilterService.SORT_NONE if the column is not sorted.

isFiltered(String, String) Method

public boolean isFiltered(String gridName, 
                          String columnName)

Check the filter state of a given column in a grid for the current request.

Parameters

gridName
the name of the grid whose column to check
columnName
the name of the column

Returns

true if the column is filtered for the grid; false otherwise.

isSorted(String, String) Method

public boolean isSorted(String gridName, 
                        String columnName)

Check the sort state of a given column in a grid for the current request.

Parameters

gridName
the name of the grid whose column to check
columnName
the name of the column

Returns

If this column in the given grid is sorted in the current URL, return true; otherwise, return false.

reset() Method

public void reset()

Clears all query information including the current page, sorts, and filters for all grid names that are on the URL. Future calls to methods that return query parameter maps will not contain any of these parameters from the current request.


reset(String) Method

public void reset(String gridName)

Clears the current page, sorts, and filters for the grid named gridName. This will leave all pages, sorts, and filters for all other grid names.

Parameters

gridName
the name of the grid whose current page, sorts, and filters to reset.

resetCurrentPage(String) Method

public void resetCurrentPage(String gridName)

Reset the current page of a specific grid. The page is reset to the first grid page.

Parameters

gridName
the name of the grid whose page to reset

toString() Method

public String toString()

Utility method thath prints the current state of a SortFilterService instance.

Overrides
Object.toString()

Returns

a String representing the state

updateRowId(ServletRequest) Method

public void updateRowId(ServletRequest request)

Update the row identifiers given the current request.

Parameters

request
the current request object