Wednesday Jun 22, 2011

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

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;


              }


        }); 



About

Talk on ADF (Mail To: vijay.x.mohan@oracle.com)

Search

Categories
Archives
« June 2011 »
SunMonTueWedThuFriSat
   
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
23
24
25
26
27
28
29
30
  
       
Today