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

Solution



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 = 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;
}
});
}

1 comment:

Anonymous said...

(v) Essential oil is not, at all, oily, but makes your eyes, water as soon as smelled or
sniffed. "This restriction would push thousands of non-smoking Suffolk County residents who utilize nicotine vaporizers into smoking areas where they would be exposed to the second hand smoke and toxic chemicals that they quit smoking to avoid," continued Babian.
Certain latex containing products such as gloves, balloons, or various types of sporting equipment may also be allergens that trigger
asthma attacks.

Feel free to surf to my site ... vaporizer
Also see my page :: vaporizer