« Forum patterns: The problem of posting to the wrong forum | Main | ADF Faces RC Declarative Components: How-to build them and how to bind them to ADF and PPR »
ADF Faces: How-to reset the sort criteria on a sortable table
By frank.nimphius | May 21, 2008
Tables in ADF Faces allow the users to sort the table values by a click onto the column header, assuming sorting has been enabled upon table creation or later configured for the columns. The question came up on OTN as of how to reset the sorting to retrieve an unordered list of table data. While you can set the table's sort criteria on the table, using a call to table.setSortCriteria(), unsetting the sort with a call to table1.setSortCriteria(null) doesn't quite work though it should.
As the old saying goes: The way to a man's heart is through his stomach. Similar in ADF, its through the binding layer when working with bound ADF Faces tables.
-
public String commandButton_action() {
-
table1.setSortCriteria(new ArrayList());
-
FacesContext fctx = FacesContext.getCurrentInstance();
-
ValueBinding vb = fctx.getApplication().createValueBinding("#{bindings}");
-
-
BindingContainer bindings = (BindingContainer)vb.getValue(fctx);
-
DCIteratorBinding dciter = (DCIteratorBinding) bindings.get("DepartmentsView1Iterator");
-
Key currentRow = dciter.getCurrentRow().getKey();
-
SortCriteria[] sc = new SortCriteria[0];
-
dciter.applySortCriteria(sc);
-
dciter.executeQuery();
-
dciter.setCurrentRowWithKey(currentRow.toStringFormat(true));
-
-
AdfFacesContext.getCurrentInstance().addPartialTarget(table1);
-
return null;
-
}
The above code unset the sort criteria on the table and then does the same on the underlying iterator. To make sure the table is reset, the iterator needs to be executed again. It would be a pity if the user looses the selected row because of this. So before executing the row, the code keeps a note of the selected row key to re-set it after the execution of the iterator.
You can also see from
-
SortCriteria[] sc = new SortCriteria[0];
-
dciter.applySortCriteria(sc);
How multiple sort criteria could be applied on the binding layer. Just create an array of oracle.jbo.SortCriteriaImpl objects that you create as
-
SortCriteriaImpl sci1 = new SortCriteriaImpl("DepartmentName",true);
-
SortCriteriaImpl sci2 = new SortCriteriaImpl("DepartmentId",true);
and then make this becoming the content of the sort array. The boolean expression determines if sorting is ascending or descending.
Frank
Topics: ADF Faces |
Comments are closed.
