How to access a row from af:table out of context
- by Vijay Mohan
Scenario : Lets say you have an adf table in a jsff and it is included as af:region inside other page(parent page).Now your requirement is to access some specific rows from the table and do some operations.
Now, since you are aceessing the table outside the context in which it is present, so first you will have to setup the context and then you can use the visitCallback mechanism to do the opeartions on table.
Here is the sample code:
=================
final RichTable table = this.getRichTable();
FacesContext facesContext = FacesContext.getCurrentInstance();
VisitContext visitContext =
RequestContext.getCurrentInstance().createVisitContext(facesContext,null,
EnumSet.of(VisitHint.SKIP_TRANSIENT,VisitHint.SKIP_UNRENDERED), null);
//Annonymous call
UIXComponent.visitTree(visitContext,facesContext.getViewRoot(),new
VisitCallback(){
public VisitResult visit(VisitContext context, UIComponent
target)
{
if (table != target)
{
return VisitResult.ACCEPT;
}
else if(table == target)
{
//Here goes the Actual Logic
Iterator selection =
table.getSelectedRowKeys().iterator();
while (selection.hasNext()) {
Object key = selection.next();
//store the original key
Object origKey = table.getRowKey();
try {
table.setRowKey(key);
Object o = table.getRowData();
JUCtrlHierNodeBinding rowData =
(JUCtrlHierNodeBinding)o;
Row row = rowData.getRow();
System.out.println(row.getAttribute(0));
}
catch(Exception ex){
ex.printStackTrace();
}
finally {
//restore original key
table.setRowKey(origKey);
}
}
}
return VisitResult.COMPLETE;
}
});