Wednesday, June 22, 2011

Handling Single/Multiple selected rows in af:table or af:tree

Accessing the table component and its attributes inside a region from the main page without setting the context,
and When we do a setRowKey() on a RichTable then the following exception is thrown.
java.lang.ClassCastException: java.util.Collections$SingletonList cannot be
cast to java.lang.Integer


public void dialogListener(DialogEvent dialogEvent) {
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 =;
//store the original key
Object origKey = table.getRowKey();
try {
Object o = table.getRowData();
JUCtrlHierNodeBinding rowData = (JUCtrlHierNodeBinding)o;
Row row = rowData.getRow();
catch(Exception ex){
finally {
//restore original key
return VisitResult.COMPLETE;

Thursday, June 09, 2011

af:paneltab programmatic disclosure

You may face MDS/Session persistance issue when you are using setDisclosed(boolean) for af:showDetailItem in af:panelTab.

You must do below after you call setDisclosed(true)

            ChangeManager cm = RequestContext.getCurrentInstance().getChangeManager();
ComponentChange truCC = new AttributeComponentChange("disclosed", true);
cm.addComponentChange(FacesContext.getCurrentInstance(), nextDynamicTab, truCC);

You must do below after you call setDisclosed(false)

            ChangeManager cm = RequestContext.getCurrentInstance().getChangeManager();
ComponentChange falseCC = new AttributeComponentChange("disclosed", false);
cm.addComponentChange(FacesContext.getCurrentInstance(), nextDynamicTab, falseCC);