BEA NetUI tags and APIs are included for backward compatibility only. For new applications, use the Beehive tags and APIs.

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

java.lang.Object
  extended by com.bea.wlw.netui.tags.databinding.SortFilterService
All Implemented Interfaces:
Serializable

public final class SortFilterService
extends Object
implements Serializable

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 JdbcControl 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 getQueryParamsMapWithSort(String, String) could be available in an anchor that is rendered at the end of this request.

See Also:
Serialized Form

Field Summary
static String PRIMARY_KEY
          Deprecated.  
static String REQUEST_KEY
          Key used to store a SortFilterSerivce object in the request.
static String ROW_IDENTIFIER
          The request key for a row identifier.
static int SORT_ASCENDING
          Constant representing an ascending sort applied to a column.
static int SORT_DESCENDING
          Constant representing a descending sort applied to a column.
static int SORT_NONE
          Constant representing no sorts applied to a column.
 
Method Summary
 void addRowIdentifier(String gridName, String columnName, Object value)
           Add a row identifier which is accessible using the getRowIdQueryParamsMap() method.
static String decodeUniqueIdentifier(javax.servlet.http.HttpServletRequest request, String gridName, String columnName)
           Decode a value from the given request's query parameters.
static String encodeUniqueIdentifier(String gridName, String columnName, Object columnValue)
           Encode a grid/column value constraint.
 int getCurrentPage(String gridName)
           Get the current page for a specific grid.
 com.bea.control.DatabaseFilter getDatabaseFilter(String gridName)
           Gets a DatabaseFilter object that contains the sorts and filters on the current request's URL.
static SortFilterService getInstance(Object object)
          Factory method to create a SortFilterService object.
 int getPageSize()
           Get the default page size.
 Map getQueryParamsMap()
           Get a Map of the query parameters that are on the current URL.
 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.
 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.
static String getQueryParamsStringOmitFilter(String prefix, String queryStr, String gridName, String columnName, String encoding)
           Internal method used to build a URL that contains all sorts / filters / pages / other parameters on the URL excluding those related to a particular grid or grid/column.
 Map getRowIdQueryParamsMap()
           Get the query params map that contains only the row identifiers that should be encoded on the URL.
 int getSortDirection(String gridName, String columnName)
           Get the sort direction of a column in a grid.
 boolean isFiltered(String gridName, String columnName)
           Check the filter state of a given column in a grid for the current request.
 boolean isSorted(String gridName, String columnName)
           Check the sort state of a given column in a grid for the current request.
 void reset()
           Clears all query information including the current page, sorts, and filters for all grid names that are on the URL.
 void reset(String gridName)
           Clears the current page, sorts, and filters for the grid named gridName.
 void resetCurrentPage(String gridName)
           Reset the current page of a specific grid.
 String toString()
           Utility method thath prints the current state of a SortFilterService instance.
 void updateRowId(javax.servlet.ServletRequest request)
           Update the row identifiers given the current request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REQUEST_KEY

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

See Also:
Constant Field Values

SORT_NONE

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

See Also:
Constant Field Values

SORT_ASCENDING

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

See Also:
Constant Field Values

SORT_DESCENDING

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

See Also:
Constant Field Values

ROW_IDENTIFIER

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

See Also:
Constant Field Values

PRIMARY_KEY

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

See Also:
Constant Field Values
Method Detail

getInstance

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.
Throws:
IllegalArgumentException - if the object parameter is null or is not a valid type from which to create a SortFilterService.

getDatabaseFilter

public com.bea.control.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.

getQueryParamsMap

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

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

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

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.

getQueryParamsStringOmitFilter

public static String getQueryParamsStringOmitFilter(String prefix,
                                                    String queryStr,
                                                    String gridName,
                                                    String columnName,
                                                    String encoding)

Internal method used to build a URL that contains all sorts / filters / pages / other parameters on the URL excluding those related to a particular grid or grid/column. If the columnName is null, the returned query parameters string will clear all filters for a grid. If the columnName is null, the returned query parameters string will clear only filters on the given column.

Parameters:
prefix - any prefix associated with the filter key
queryStr - the current query string
gridName - the name of the grid whose filters to remove
columnName - the name of a column whose filters to remove
encoding - the encoding of the requesting page
Returns:
a query parameters string that omits filters for the correct grid / column
Exclude:

updateRowId

public void updateRowId(javax.servlet.ServletRequest request)

Update the row identifiers given the current request.

Parameters:
request - the current request object
Throws:
IllegalStateException - if the request object is null or is not an HttpServletRequest

reset

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

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

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

getCurrentPage

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

getPageSize

public int getPageSize()

Get the default page size.

Returns:
the default size of a page, 10.

isSorted

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.

getSortDirection

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:
SORT_ASCENDING if the column is sorted in ascending order, SORT_DESCENDING if the column is sorted in descending order, and SORT_NONE if the column is not sorted.

isFiltered

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.

encodeUniqueIdentifier

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

decodeUniqueIdentifier

public static String decodeUniqueIdentifier(javax.servlet.http.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

addRowIdentifier

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

Add a row identifier which is accessible using the 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.

toString

public String toString()

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

Overrides:
toString in class Object
Returns:
a String representing the state

BEA NetUI tags and APIs are included for backward compatibility only. For new applications, use the Beehive tags and APIs.