How to access a row from af:table out of context

Posted by Vijay Mohan on Oracle Blogs See other posts from Oracle Blogs or by Vijay Mohan
Published on Wed, 22 Jun 2011 03:39:34 -0700 Indexed on 2011/06/22 16:26 UTC
Read the original article Hit count: 262

Filed under:

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;


              }


        }); 



© Oracle Blogs or respective owner

Related posts about /Oracle