Created
April 29, 2011 08:14
-
-
Save esaounkine/948035 to your computer and use it in GitHub Desktop.
Accumulative sorting in ADF 10g tables - backing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import oracle.adf.view.faces.event.SortEvent; | |
import oracle.adf.view.faces.model.SortCriterion; | |
import oracle.adf.view.faces.component.core.data.CoreTable; | |
import java.util.List; | |
import java.util.ArrayList; | |
public class Customers { | |
public void onSort(SortEvent se) { | |
// get selected criterion | |
List sortList = se.getSortCriteria(); | |
SortCriterion currentSortCriterion = (SortCriterion)sortList.get(0); | |
// get previously selected criteria | |
ArrayList persistentSortList = getCustomerTableSortCriteria(); | |
// the rest of the code expands the sort criteria, applies the new criteria list to the table and saves the criteria list for the future | |
ArrayList updatedSortList = new ArrayList(); | |
updatedSortList.add(0, currentSortCriterion); | |
for(Object o : persistentSortList) { | |
updatedSortList.add((SortCriterion)o); | |
} | |
CoreTable ct = (CoreTable)se.getComponent(); | |
ct.setSortCriteria(updatedSortList); | |
setCustomerTableSortCriteria(updatedSortList); | |
} | |
public static final String CUSTOMER_TABLE_SORT_CRITERIA = "customerTableSortCriteria"; | |
/* As the sort criteria returned at any call to the onSort method have request scope, | |
* I use a session scoped bean that I call viewScope (I clean it up every time the viewId is changed, meaning that user has entered another page) which in fact is a java.util.HashMap. | |
* The method getCustomerTableSortCriteria() returns the Object under key CUSTOMER_TABLE_SORT_CRITERIA stored in viewScope. | |
* Naturally instead of viewScope one can use any other session scoped bean to store the ArrayList of SortCriterion objects. | |
*/ | |
private ArrayList getCustomerTableSortCriteria() { | |
ArrayList sortCriteria = (ArrayList)viewScope.get(CUSTOMER_TABLE_SORT_CRITERIA); | |
if(sortCriteria == null) { | |
sortCriteria = new ArrayList(); | |
setCustomerTableSortCriteria(sortCriteria); | |
} | |
return sortCriteria; | |
} | |
private void setCustomerTableSortCriteria(ArrayList sortCriteria) { | |
viewScope.put(CUSTOMER_TABLE_SORT_CRITERIA, sortCriteria); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment