This tutorial illustrates how to update the selected rows attributes using an af:table component with checkboxes. By applying successive queries on a table, the state of the binded iterator changes and it will contain only the rows displayed in UI. In the following sections, we’ll present 2 mechanisms to update the state of all selected rows, even if those aren’t contained in the current applied view criteria on the table.
The demo application is based on the HR schema and displays in a table rows of users and based on selection and multiple queries, it can be updated the current status (1- Active, 0-Inactive). The first approach uses a mechanism of stored lists and the second a way to remove/reapply successive the view criteria on the iterator.
Method 1
The first approach is to use a List of selected rows IDs updated at each row checkbox selection. Also it will be displayed a global counter to visualize the number of selected items. At each client event of row selection, the stored list is updated based on an algorithm illustrated below. Now, multiple queries and selections from different states of the iterator will be stored into an internal list and the counter will display the proper number of items.
private void refreshSelectedRows() {
DCIteratorBinding it = ADFUtils.findIterator(ITERATOR_NAME);
RowSetIterator rit = it.getRowSetIterator();
selectedCount = new Long(selectedList.size());
LinkedList selectedNewList = new LinkedList<Number>();
LinkedList allNewList = new LinkedList<Number>();
Row r = rit.first();
allNewList.add((String)r.getAttribute("Username"));
if (isSelected(r)) {
selectedCount++;
selectedNewList.add((String)r.getAttribute("Username"));
}
while (rit.hasNext()) {
r = rit.next();
allNewList.add((String)r.getAttribute("Username"));
if (isSelected(r)) {
selectedCount++;
selectedNewList.add((String)r.getAttribute("Username"));
}
}
Iterator itNew = selectedNewList.iterator();
while (itNew.hasNext()) {
String key = (String)itNew.next();
if (!selectedList.contains(key)) {
selectedList.add(key);
} else {
selectedCount--;
}
}
LinkedList selectedListCopy = new LinkedList<String>();
selectedListCopy.addAll(selectedList);
Iterator itP = selectedListCopy.iterator();
while (itP.hasNext()) {
String key = (String)itP.next();
if (allNewList.contains(key) && (!selectedNewList.contains(key))) {
selectedCount--;
selectedList.remove(key);
}
}
AdfFacesContext.getCurrentInstance().addPartialTarget(JSFUtils.findComponentInRoot("pgl3"));
}
The changeStatus operation is performed regarding the selected list of row IDs (selectedList). For each row with the specific ID stored in the selected list we set the attribute Status to a proper value like in the example below. It is important that the update operation it will be performed on a second iterator without any view criteria applied.
public void changeStatus(ActionEvent actionEvent) {
Iterator it = selectedList.iterator();
DCIteratorBinding rptWVCIt = ADFUtils.findIterator(ITERATOR_WVC_NAME);
while (it.hasNext()){
String item = (String)it.next();
Row row = getRowByUsername(rptWVCIt, item);
row.setAttribute("Status", 1);
}
ADFUtils.getApplicationModuleForDataControl(AMDC).getTransaction().commit();
AdfFacesContext.getCurrentInstance().addPartialTarget(getTable());
}
The method to find the row after its ID is (we consider that the Username attribute is the primary key of the table):
public Row getRowByUsername(DCIteratorBinding rptWVCIt, String key) {
RowSetIterator iterator = rptWVCIt.getRowSetIterator();
Row next = iterator.first();
if (next != null) {
if (((String)next.getAttribute("Username")).equals(key)) {
return next;
}
}
while (iterator.hasNext()) {
next = iterator.next();
String testedKey = (String)next.getAttribute("Username");
if (((String)next.getAttribute("Username")).equals(testedKey)) {
iterator.reset();
return next;
}
}
iterator.reset();
return null;
}
This method is better than successive removing/applying view criteria on current iterator regarding the speed (e.g. a select all operation and a change status on over 1.000 rows takes sec, much better than over 12 sec with the second algorithm). The drawback is that it must carefully manage the list of selected rows and the counter. The demo page looks like:

Method 2
The second method uses the principle of retrieving the applied view criterias and removing those identified. After all the work is done, the removed criterias can be easily restored like in the code below:
public void changeStatusMethod2(ActionEvent actionEvent) {
DCIteratorBinding it = ADFUtils.findIterator(ITERATOR_NAME);
ViewCriteria vcs[] =
it.getViewObject().getViewCriteriaManager().getApplyViewCriterias(ViewCriteria.CRITERIA_MODE_QUERY);
for (int i = 0; i < vcs.length; i++) {
it.getViewObject().getViewCriteriaManager().removeApplyViewCriteriaName(vcs[i].getName());
}
//parse all selected rows and change Status attribute
//put back the previously removed view criterias
for (int i = 0; i < vcs.length; i++) {
//append the view crietria to the existing ones
it.getViewObject().getViewCriteriaManager().applyViewCriteria(vcs[i],true);
}
}
This approach doesn’t require a complicated management like storing the selected rows in a list, but is slower because of the successive operations on iterator’s view criterias. The source code can be downloaded here.

The HR schema doesnot have the 2 tables that u work on them i hope that u send the two tables script Thanks a lot
Ahmed
But I do them by adding a new database diagram and i drag the entity on it and i generate it into the db and it works fine now
Hi Ahmed,
Glad to hear you configured to work.
Hello I discovered your own weblog referred to as GEBS | Checkbox row selection – multiple queries and selected rows update through msn lookup engine in addition to ive pinged this your current link http://www.gebs.ro/blog/oracle/checkbox-row-selection-multiple-queries-and-selected-rows-update/ should you do not mind