Advanced Tables are the recommended approach for rendering tables in OA Framework since they offer both declarative support in addition to programmatic control. One of the features available in Advanced Tables is the ability to sort columns by clicking on the column header. In this post, we will discuss how sort events are handled in Advanced Tables.
In general, the following table events are defined for an Advanced Table.
Navigation – Triggered when a user selects the Next or Previous link to navigate between different ranges of rows.
Sorting – Triggered when a user selects a beveled column heading to sort that column in ascending or descending order.
Insertion of a new row – Triggered when a user selects the Add Another Row button.
Recalculate column Total – Triggered when a user selects the Recalculate button to update the column total.
Detail Disclosure – Triggered when a user selects the Hide or Show link to collapse or expand the detail disclosure region.
Table Control – Triggered when a user selects the Action/Navigation button in the table Control bar.
These events are handled during processFormRequest and OA Framework automatically sets the following parameters based on which event was triggered:
SOURCE_PARAM – indicates the source of the event that is generating the current browser request.
EVENT_PARAM – indicates the event generated by the table.
VALUE_PARAM – indicates a value that is relevant to a particular event. For the sort event, it points to the column on which the sorting is done.
SIZE_PARAM – indicates the number of rows currently displayed in the table (relevant only to the navigation event).
STATE_PARAM – indicates the current sort state (ascending or descending) of the column on which sorting is invoked (relevant only for the sort event).
These parameters can be accessed programatically using pageContext.getParameter(<PARAMETER_NAME>). For example, pageContext.getParameter(SOURCE_PARAM) will fetch the name of the Advanced Table from which an event was triggered.
Below is the Advanced Table, xxAdvTab based on the View Object, xxAdvTabVO.
I have added the following code in the processFormRequest section of the controller in order to display the value of the event parameters during runtime.
if ("xxAdvTab";.equals(pageContext.getParameter(SOURCE_PARAM))) {OAException mesg = new OAException("SOURCE_PARAM= " +pageContext.getParameter(SOURCE_PARAM) +", EVENT_PARAM= " +pageContext.getParameter(EVENT_PARAM) +", VALUE_PARAM= " +pageContext.getParameter(VALUE_PARAM) +", SIZE_PARAM= " +pageContext.getParameter(SIZE_PARAM) +", STATE_PARAM= " +pageContext.getParameter(STATE_PARAM) ,OAException.INFORMATION); pageContext.putDialogMessage(mesg);}
1. Clicking on the Employee Name column sorts it in ascending order and sets the values of the parameters.
SOURCE_PARAM stores the name of the Advaced Table, xxAdvTab.
EVENT_PARAM stores the event, which is sort in this case.
VALUE_PARAM stores the column on which the sort was performed, in this case the second column. The value is 1 since the columns are numbered from 0 onwards.
SIZE_PARAM is null since it is used only in the Navigation event.
STATE_PARAM indicates the current sort state, ie, the sort state when the event was triggered. When the event was triggered, the Employee Name was in an unsorted state hence its value is null.
2. Clicking on the Employee Name column again sorts it in descending order and sets the values of the parameters.
All the parameters have the same values except for STATE_PARAM which is now ascending because when the event was triggered the Employee Name column was already sorted in the ascending order.
3. If the Employee Id column is now sorted, the parameters will have the following values.
SOURCE_PARAM stores the name of the Advaced Table, xxAdvTab.
EVENT_PARAM stores the event, which is sort in this case.
VALUE_PARAM shows 0 since the sort was performed on the first column.
SIZE_PARAM is null since it is used only in the Navigation event.
STATE_PARAM shows null since it shows the current sort state of the column on which the sort was invoked. Employee Id was in an unsorted state hence the value is null.
This brings us to a limitation of the STATE_PARAM parameter, it gives us the current sort state of the column which is being sorted. It does not provide the sort state of the Advanced Table as a whole. In the previous step, even though the Advanced Table was sorted based on the Employee Name in descending order, the STATE_PARAM parameter was set to null. One way of working around this is to get the sort status of the Advanced Table from the ORDER_BY clause of the underlying table. This can be done by changing the controller code as shown below:
//get a handle to the View Object OAViewObject viewObject = (OAViewObject)oam.findViewObject("xxAdvTabVO1"); if ("xxAdvTab".equals(pageContext.getParameter(SOURCE_PARAM))) {OAException mesg = new OAException("SOURCE_PARAM= " +pageContext.getParameter(SOURCE_PARAM) +", EVENT_PARAM= " +pageContext.getParameter(EVENT_PARAM) +", VALUE_PARAM= " +pageContext.getParameter(VALUE_PARAM) +", SIZE_PARAM= " +pageContext.getParameter(SIZE_PARAM) +", STATE_PARAM= " +pageContext.getParameter(STATE_PARAM) //display the ORDER_BY clause of the VO +", VO ORDER_BY clause= " +viewObject.getOrderByClause() ,OAException.INFORMATION); pageContext.putDialogMessage(mesg);}
4. Performing Steps#1, 2 and 3 once again provides the following values of the parameters.
The standard parameters still show the same values as in Step#3, but the VO ORDER_BY clause now correctly shows that the Advanced Table was already sorted based on the Employee Name in the descending order when the sort event was triggered.
Refer to the chapter on Advanced Tables in the Oracle Application Framework Developers Guide for additional details.