To use this type of JPO, you must set the table column parameter sort type to other, and the table column setting Sort Program must contain the name of the JPO. You can use the multiColumnSort, sortColumnName, and sortDirection URL parameters to control sorrting for a table, or you can create a custom sorting program.
See URL Parameters Accepted by emxTable.jsp and emxTableEdit.jsp.
A JPO defined as a Sort Program must follow these rules:
- The JPO class must extend emxCommonBaseComparator
JPO. The framework installs the emxCommonBaseComparator JPO. It contains the base implementations
required to make custom sorting work.
public class ${CLASSNAME} extends
${CLASS:emxCommonBaseComparator}
{
}
- The JPO class must define a default constructor as shown.
// default constructor
public ${CLASSNAME} ( )
{
}
- The class must define a method called compare(..).
The template for the compare method definition is:
public int compare(Object object1, Object object2)
{
// Logic to compare the two objects and return the integer
value
}
The input parameters and return values of the compare
method are:
- param object1--the first object to compare.
- param object2--the second object to compare.
- Returns:
- A negative integer if first argument is less than second argument.
- A zero if the arguments are equal.
- A positive integer if the first argument is greater than second argument.
- object1 and object2 is of type Map.
- The information about the sort and Map objects passed in are stored
in keys field of base comparator (emxCommonBaseComparator). The keys
field is a Map object containing these keys.
Key Name |
Description |
Type |
Specifies the type of sort and should always
be set to "other." |
columnKey |
Identifies the key name to get sort column values
from Map object1 and object2. |
direction |
Direction of sort: ascending or descending. |