Within SAP NetWeaver 04s the Web Dynpro Table UI element was significantly enhanced with additional features like grouped columns, cell variants, single markable cells, standard cells with adaptable designs or table popins. You can find more detailed information about the extended Table UI element within theSAP Online Help documentation.
Before we will publish an updated version of theWeb Dynpro table tutorial on SDN we want to provide an enhanced version of the highly useful TableSorter class which can be reused in all Web Dynpro applications running in SAP NetWeaver 04s.
Functionality of the NW04s-adapted TableSorter class
Adapted to SAP NetWeaver 04s the enhanced TableSorter class provides the following functionality:
Adapted Table UI element event binding: In NW04 the TableSorter implements the functionality to display the sort icons in the column headers and to store the sort state for each column. In NW04s this functionality is generically provided by the Table-UIElement itself. The new TableSorter is now based on the new onSort-event of the Table UI element instead of the onAction-event of the TableColumn UI element. The sort a and sort order icons are automatically displayed for sortable tables.
Restricted sorting to a subset of columns: In order to restrict sorting to a subset of table columns in NW04, the onAction-event of the corresponding TableColumn UI elements was bound to the action Sort. In NW04s the interaction model between the table and the TableSorter class is completely based on the table's onSort-event and the event parameters 'selected column' and 'sort direction'. Within an additional constructor methodTableSorter(IWDTable table, IWDAction sortAction, Map comparators, String[] sortableColumns) a subset of sortable table columns can be specified. The TableSorter class sorts all columns by default.
Definition of custom comparators: The new TableSorter uses a java.util.Map to define alternative comparators instead of an Array because this solution is more flexible for further enhancements. As key for the map, the column ID is used.
Support of grouped columns: The new TableSorter can deal withGroupedColumns, which were added in NW04s.
Language specific sorting : Strings are compared with the java.text.Collator class to allow language specific sorting.
Support of non-singleton child node attributes: The previous TableSorter could only sort those olumns which were directly bound to an attribute of the table's root context node. Attributes of non-singleton child nodes of this node, which were displayed in the same table, were not sortable. The NW04s-TableSorter can now sort these columns too.
How to apply the TableSorter class
- Add the TableSorter class TableSorter.java to the new package folder src/packages/com/sap/tc/webdynpro/tests/utils
- Declare a new context attribute TableSorter of type com.sap.tc.webdynpro.tests.utils.TableSorter within the view controller context.
- Declare a new action with name Sort (or SortCustomers in this example) and with the associated action event handler onActionSort() to the view controller.
- Implement the following source code in the wdDoModifyView()-hook-method of the view controller:
public static void wdDoModifyView(
IPrivateWork wdThis, IPrivateWork.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
{
//@@begin wdDoModifyView
if (firstTime) {
IWDTable table = (IWDTable) view.getElement("CustomerTable");
wdContext.currentContextElement().setCustomerTableSorter(
new TableSorter(table, wdThis.wdGetSortCustomersAction(), null, new String[] { "CustomerTable_Name" }));
}
//@@end
}
- In case you apply the new generic UI service which automatically creates all custom extension fields (only supported for Adaptive RFC models) in the view layout you must additionally invoke the IWDView interface. By default, custom extension fields are created automatically after the first call to wdDoModifyView() that follows the creation of a parent element (e.g. table) that aggregates custom extension fields. Of course, this only relates to custom extension fields that have been explicitly configured by an administrator for the current user role. In case you want to modify these custom extension fields (e.g. making table columns sortable) you must call the method IWDView.nowCreateAllCustomExtensionFields() before:
public static void wdDoModifyView(IPrivateWork wdThis, IPrivateWork.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
{
//@@begin wdDoModifyView
if (firstTime) {
view.nowCreateAllCustomExtensionFields();
IWDTable table = (IWDTable) view.getElement("CustomerTable");
wdContext.currentContextElement().setCustomerTableSorter(
new TableSorter(table, wdThis.wdGetSortCustomersAction(), null, new String[] { "CustomerTable_Name" }));
}
//@@end
}
- Organize imports within the view controller class so that import com.sap.tc.webdynpro.tests.utils.TableSorter; is added.
- Implement the following source code in the action event handler onActionSort() (or onActionSortCustomers in this example).
//@@begin javadoc:onActionSortCustomers(ServerEvent)
/** Declared validating event handler. */
//@@end
public void onActionSortCustomers(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionSortCustomers(ServerEvent)
wdContext.currentContextElement().getCustomerTableSorter().sort(wdEvent, wdContext.nodeCustomers());
//@@end
}
Download New NW04s-TableSorter class
You can download the Web Dynpro sample project WDTableSorter_NW04s.zip which applies the enhanced NW04s-TableSorter class. This sample is based on thecontext tutorial application.
Enjoy Web Dynpro,
Bertram Ganz, Jens Pflueger, SAP AG