<templateDefinition targetNamespace="http://xmlns.oracle.com/uix/demo"
localName="sortableColumn">
<type base="data:column">
<attribute name="key" javaType="string"/>
<attribute name="header" javaType="string"/>
<!-- by default this column will be sortable.
However, if this attribute is set to 'false',
then this column will not be sortable -->
<attribute name="sortable" javaType="boolean"/>
</type>
<content>
<column>
<attributeMap><rootAttributeMap/></attributeMap>
<columnHeader>
<sortableHeader text="${uix.rootAttr.header}"
value="${uix.rootAttr.key}">
...
</sortableHeader>
</columnHeader>
<contents>
<text text="${uix.current[uix.rootAttr.key]}"/>
</contents>
</column>
</content>
</templateDefinition>
<sortableHeader text="${uix.rootAttr.header}"
value="${uix.rootAttr.key}">
<boundAttribute name="sortable">
<if>
<!-- is this table currently sorted by the bean property displayed by
this column? -->
<comparison type="equals">
<dataObject select="sortBy">
<contextProperty select="demo:tableState"/>
</dataObject>
<dataObject source="${uix.rootAttr.key}""/>
</comparison>
<!-- if so, then we need to return either "ascending" or "descending"
depending on the sortOrder -->
<if>
<dataObject select="sortOrder">
<contextProperty select="demo:tableState"/>
</dataObject>
<fixed>ascending</fixed>
<fixed>descending</fixed>
</if>
<!-- Otherwise, we might be sortable (though not sorted in any
particular order) as long as the user has not set the sortable
attribute to false -->
<if>
<defaulting>
<dataObject source="${uix.rootAttr.sortable}"/>
<!-- by default, we are sortable -->
<fixed text="true"/>
</defaulting>
<fixed>yes</fixed>
<fixed>no</fixed>
</if>
</if>
</boundAttribute>
</sortableHeader>
UserData uData = _getUserData(..); // from HttpSession
TableState tState = uData.getBookTableState();
String valueParam = event.getParameter(UIConstants.VALUE_PARAM);
// create a Comparator that will sort our list of Book beans by the
// required property:
BeanComparator sorter = new BeanComparator(Book.class, valueParam);
tState.setSortBy(valueParam, sorter);
UserData uData = _getUserData(..); // from HttpSession
TableState tState = uData.getBookTableState();
String eventName = event.getName();
String valueParam = event.getParameter(UIConstants.VALUE_PARAM);
// This handles detail disclosure. The event must have a "value"
// parameter which is the index of the row to disclose or
// undisclose. This index is based at zero. The "value" might also be
// VALUE_SHOW_ALL which signals a show-all or hide-all.
if (UIConstants.VALUE_SHOW_ALL.equals(valueParam))
{
// if the event is "show" then do a show-all. Otherwise, do a hide-all:
tState.showAllDetails(UIConstants.SHOW_EVENT.equals(eventName));
}
else
{
int value = Integer.parseInt(valueParam);
tState.toggleDisclosed(value);
}
// the data that is coming from the client are form elements inside a
// table. therefore, we can use some FlattenedDataSet implementation to
// get at the data:
PageEventFlattenedDataSet clientData =
new PageEventFlattenedDataSet(event, "books");
// get the indices that were selected (note that these indices are
// relative to the current record set):
int[] selection = SelectionUtils.getSelectedIndices(clientData);
UserData uData = _getUserData(..); // from HttpSession
TableState tState = uData.getBookTableState();
List tableData = tState.getTableData();
// this is the offset to add to convert a selection index into an actual
// book index. Note that the -1 is significant since getStartIndex is
// based at 1 and the selection indices are based at zero:
int currentRecordOffset = tState.getStartIndex() - 1;
// BEGIN handle select-all
// ** select-all not yet implemented **
// END handle select-all
// if we loop forward then the books we delete first will affect the
// indices of the books we delete second. So must loop backwards:
for(int i=selection.length-1; i>=0; i--)
{
// each selected index is relative to the current record set. therefore
// we need to add an offset to get the index of the actual book:
tableData.remove(selection[i] + currentRecordOffset);
}
// BEGIN handle select-all
// check to see if user has picked select-all:
Object selectMode = clientData.selectValue(null /*renderingContext*/,
UIConstants.SELECT_MODE_KEY);
if ("all".equals(selectMode))
{
// we need to handle select-all+delete carefully - we can't just delete
// everything since the user might have unselected something in the
// current record set. so first, delete everything upto (but not
// including) the current record set:
tableData.subList(0, currentRecordOffset).clear();
// now the current record set starts at index 0:
currentRecordOffset = 0;
// second, delete everything that follows the current record set:
int sz = tableData.size();
int firstIndexOnNextPage = tState.getBlockSize();
// check to make sure that there are records on the next page:
if (firstIndexOnNextPage < sz) tableData.subList(firstIndexOnNextPage, sz).clear();
// third, continue deleting the selected records in the current record
// set:
}
// END handle select-all
<handlers>
<!-- the examples in this file require an HttpSession to be created
for each user -->
<event name="null">
<method class="oracle.cabo.doc.demo.table.MockupUtils"
method="createSession"/>
</event>
<!-- handle all the table events -->
<event name="goto sort show hide">
<method class="oracle.cabo.doc.demo.table.MockupUtils"
method="handleTableEvent"/>
</event>
</handlers>