12 Replies Latest reply: Sep 17, 2013 4:26 AM by 1004526 RSS

    selectionListener on Table

    1004526

      Hello All,

       

      I am using jdev 11.1.1.6

       

      I am trying to detect click on a row, below piece of code is working. s.o.p is getting printed.

       

      In jsff

       

                                        <af:table value="#{pageFlowScope.Bean.List}" var="temp"

                                        rows="150"

                                        id="dc_tl1" width="680"

                                        selectionListener="#{pageFlowScope.Bean.selectedRow_action}"

                                        rowSelection="single" contentDelivery="immediate"

                                        inlineStyle="font-weight:normal;">                                  

                                            <af:column id="dc_cf5" clientComponent="true" headerText="Value" >

                                             <af:outputText value="#{temp.value1}" escape="false"

                                                            id="dc_ot6"/>

                                            </af:column>

                                        </af:table>

       

      In backing bean

       

          public void selectedRow_action(SelectionEvent selectionEvent) {

          System.out.println("Row is sucessully clicked");

          }

       

      Proceeding from here, I tried to use below piece of code from the forum, but was not able to use it

       

      Snippet 1.

       

      public void selectedRow_action(SelectionEvent selectionEvent) {

      RichTable _table = (RichTable) selectionEvent.getSource();

      CollectionModel tableModel = (CollectionModel) table.getValue();

       

      JUCtrlHierBinding adfTableBinding = (JUCtrlHierBinding) tableModel.getWrappedData();

      DCIteratorBinding tableIteratorBinding = adfTableBinding.getDCIteratorBinding();

      Object selectedRowData = table.getSelectedRowData(); // This returns null........

      JUCtrlHierNodeBinding nodeBinding = (JUCtrlHierNodeBinding) selectedRowData;

      System.out.println("***** "+_nodeBinding.getAttribute("sponsorId"));

      }

       

      <af:table value="#{bindings.sponsorType.collectionModel}" var="row"

      rows="#{bindings.sponsorType.rangeSize}"

      emptyText="#{bindings.sponsorType.viewable ? 'No data to display.' : 'Access Denied.'}"

      fetchSize="#{bindings.sponsorType.rangeSize}"

      rowBandingInterval="0"

      binding="#{backingBeanScope.EditSponsorDetails.spSearchTable}"

      selectionListener="#{backingBeanScope.EditSponsorDetails.selectedRow_action}"

      selectedRowKeys= "#{bindings.sponsorType.collectionModel.selectedRow}"

      id="spSearchTable"

       

      Snippet 2

       

      <af:table value="#{bindings.Employees.collectionModel}" var="row"

      rows="#{bindings.Employees.rangeSize}"

      emptyText="#{bindings.Employees.viewable ? 'No data to display.' : 'Access Denied.'}"

      fetchSize="#{bindings.Employees.rangeSize}"

      rowBandingInterval="0"

      selectionListener="#{EmpTableBean.onTableNodeSelection}"

      rowSelection="single" id="t1">

      </af:table>

       

      public void onTableNodeSelection(SelectionEvent selectionEvent) {

      resolveMethodExpression("#{bindings.Employees.collectionModel.makeCurrent}",

      null, new Class[] { SelectionEvent.class },

      new Object[] { selectionEvent });

      RichTable object = (RichTable)selectionEvent.getSource();

      Row row = null;

      for (Object facesRowKey : object.getSelectedRowKeys()) {

      object.setRowKey(facesRowKey);

      Object o = object.getRowData();

      JUCtrlHierNodeBinding rowData = (JUCtrlHierNodeBinding)o;

      row = rowData.getRow();

      }

      System.out.println(row.getAttribute("FirstName").toString());

      }

       

      public Object resolveMethodExpression(String expression, Class returnType,

      Class[] argTypes,

      Object[] argValues) {

      FacesContext facesContext = FacesContext.getCurrentInstance();

      Application app = facesContext.getApplication();

      ExpressionFactory elFactory = app.getExpressionFactory();

      ELContext elContext = facesContext.getELContext();

      MethodExpression methodExpression =

      elFactory.createMethodExpression(elContext, expression, returnType,

      argTypes);

      return methodExpression.invoke(elContext, argValues);

      }


      createMethodExpression gives me error.


      How can i use the above code for me.  Also what will be import statements (I guess my imports are wrong)

        • 1. Re: selectionListener on Table
          Cvele_new_account

          "createMethodExpression gives me error."


          What error ? Any stack trace ?

          • 2. Re: selectionListener on Table
            Timo Hahn

            It would be easier if you tell us what you try to du exactly.  Your choice looks like you want to mimick the table selection listener, but you don't do anything else.

            Please read http://www.oracle.com/technetwork/developer-tools/adf/learnmore/23-generic-table-selection-listener-169162.pdf which comes with a sample http://www.oracle.com/technetwork/developer-tools/adf/learnmore/23-genericselectionlistener-168505.zip

            Weich dies what you are trying to do.

             

            Timo

            • 3. Re: selectionListener on Table
              Subramanian Meyyappan

              import javax.el.ELContext;

              import javax.el.ExpressionFactory;

               

               

              import javax.el.MethodExpression;

               

               

              import javax.faces.application.Application;

              import javax.faces.context.FacesContext;

               

               

              import oracle.adf.controller.TaskFlowId;

               

               

               

              import oracle.adf.view.rich.component.rich.data.RichTable;

               

               

              import oracle.jbo.Row;

              import oracle.jbo.uicli.binding.JUCtrlHierNodeBinding;

              check this import are you using?

              • 4. Re: selectionListener on Table
                1004526

                I am using below piece of code

                 

                 

                    public void selectedRow_action(SelectionEvent selectionEvent) {

                        RichTable table = (RichTable)selectionEvent.getSource();

                        CollectionModel tableModel = (CollectionModel)table.getValue();

                        JUCtrlHierBinding adfTableBinding = (JUCtrlHierBinding)tableModel.getWrappedData();

                        DCIteratorBinding tableIteratorBinding = adfTableBinding.getDCIteratorBinding();

                        Object selectedRowData = table.getSelectedRowData();

                        JUCtrlHierNodeBinding nodeBinding = (JUCtrlHierNodeBinding)selectedRowData;

                    }

                 

                 

                   this line --> CollectionModel tableModel = (CollectionModel)table.getValue();

                 

                 

                   gives below error

                 

                 

                The Faces lifecycle receives unhandled exceptions in phase 5 INVOKE_APPLICATION

                javax.el.ELException: java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.apache.myfaces.trinidad.model.CollectionModel

                • 5. Re: selectionListener on Table
                  1004526

                  I used the code from http://www.oracle.com/technetwork/developer-tools/adf/learnmore/23-genericselectionlistener-168505.zip

                   

                   

                   

                  Backing bean functions

                   

                   

                   

                  public void onTableSelect(SelectionEvent selectionEvent) {

                      

                       //pre-trigger code

                       makeCurrent(selectionEvent);

                       //post-trigger code

                                        

                  }

                   

                   

                  //test row selection

                  public String print_action() {

                       BindingContext bindingContext = BindingContext.getCurrent();

                       BindingContainer bindings = bindingContext.getCurrentBindingsEntry();

                      

                       DCIteratorBinding iter = (DCIteratorBinding) bindings.get("DepartmentsView1Iterator");

                       Row rw = iter.getCurrentRow();

                      

                       //print

                      

                       System.out.println("Selected Row Data: "+rw.getAttribute(0)+" "+rw.getAttribute(1));

                      

                       return null;

                  }

                   

                      public static void makeCurrent(SelectionEvent selectionEvent){       

                         

                          RichTable _table = (RichTable) selectionEvent.getSource();

                          //the Collection Model is the object that provides the structured data

                          //for the table to render

                          CollectionModel   _tableModel = (CollectionModel) _table.getValue();

                          //the ADF object that implements the CollectionModel is JUCtrlHierBinding. It

                          //is wrapped by the CollectionModel API

                          JUCtrlHierBinding _adfTableBinding = (JUCtrlHierBinding) _tableModel.getWrappedData();

                          //Acess the ADF iterator binding that is used with ADF table binding

                          DCIteratorBinding _tableIteratorBinding = _adfTableBinding.getDCIteratorBinding();

                         

                          //the role of this method is to synchronize the table component selection

                          //with the selection in the ADF model

                          Object _selectedRowData = _table.getSelectedRowData();

                          //cast to JUCtrlHierNodeBinding, which is the ADF object that represents

                          //a row

                          JUCtrlHierNodeBinding _nodeBinding = (JUCtrlHierNodeBinding) _selectedRowData;

                          //get the row key from the node binding and set it as the current row in the

                          //iterator

                          Key _rwKey = _nodeBinding.getRowKey();

                          _tableIteratorBinding.setCurrentRowWithKey(_rwKey.toStringFormat(true));       

                      }

                     

                   

                   

                  and

                   

                   

                  jsff

                   

                   

                                                   <af:table value="#{pageFlowScope.Bean.List}" var="temp"

                                                    rows="1500" rowBandingInterval="0"

                                                    id="dc_t2" width="680"

                                                    selectionListener="#{pageFlowScope.Bean.onTableSelect}"

                                                    rowSelection="single" contentDelivery="immediate"

                                                    inlineStyle="font-weight:normal;" >                                  

                                                        <af:column id="dc_c1" align="center" clientComponent="true" headerText="Heade1" width="150"

                                                        sortProperty="Name1" sortable="true" >

                                                         <af:outputText value="#{temp.value1}" escape="false"

                                                                        id="dc_ot1"/>

                                                        </af:column>

                                                    </af:table>

                   

                   

                   

                  List is populated in Bean.java

                   

                   

                   

                  I am getting error as below

                   

                   

                  java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.apache.myfaces.trinidad.model.CollectionModel

                  • 6. Re: selectionListener on Table
                    Cvele_new_account

                    This is because of:

                     

                    af:table value="#{pageFlowScope.Bean.List}

                     

                    So, you use ArrayList as a table value,  and, in the next line:

                     

                    CollectionModel tableModel = (CollectionModel)table.getValue();

                     

                    you are trying to cast ArrayList to the CollectionModel

                    You need to cast table value to the ArrayList (i.e. some List impelementation)

                    • 7. Re: selectionListener on Table
                      1004526

                      I am obliged to use ArrayList,

                      Is there any way to tackle this issue...

                      • 8. Re: selectionListener on Table
                        1004526

                        Any Advise ?

                        • 9. Re: selectionListener on Table
                          Cvele_new_account

                          Lets go step by step, take a look at comments I gave you bellow:

                          1004526 wrote:

                           

                          I am using below piece of code

                           

                           

                              public void selectedRow_action(SelectionEvent selectionEvent) {

                                  RichTable table = (RichTable)selectionEvent.getSource();

                                  Object selectedRowData = table.getSelectedRowData();

                                  // CVELE: TAKE A LOOK TO SEE WHAT IS A CLASS OF selectedRowData.

                                  // Is this JUCtrlHierNodeBinding ? Check, and let me know:

                                  System.out.println("selRowData class " + selectedRowData.getClass().getName());

                              }

                           

                           

                          • 10. Re: selectionListener on Table
                            1004526

                            I put this code..

                             

                             

                                    public void selectedRow_action(SelectionEvent selectionEvent) {

                                    RichTable table = (RichTable)selectionEvent.getSource();

                                    Object selectedRowData = table.getSelectedRowData();

                                    System.out.println("selRowData class " + selectedRowData.getClass().getName());  --> o/p is selRowData class com.companyName.projectName.BeanName

                                }

                             

                             

                            Name->table Type->RichTable

                            Name->selectedRowData Type->BeanName

                             

                             

                             

                             

                            public class BeanName{

                             

                             

                                private String Value1;

                                private String Value2;

                                private Date   Value3;

                             

                             

                                //getter and setters.

                             

                             

                            }

                             

                            class is not of JUCtrlHierNodeBinding type

                            • 11. Re: selectionListener on Table
                              Cvele_new_account

                              So, just cast selectedRowData into the BeanName, and you will get the selected Row:

                               

                              public void selectedRow_action(SelectionEvent selectionEvent) {

                                      RichTable table = (RichTable)selectionEvent.getSource();

                                      Object selectedRowData = table.getSelectedRowData();

                                      BeanName selRow = (BeanName)selectedRowData;

                                  }

                               

                              This is what you wanted, right? Or I am wrong ?

                              1004526 wrote:

                               

                              Name->selectedRowData Type->BeanName

                               

                               

                               

                               

                              • 12. Re: selectionListener on Table
                                1004526

                                Thank you Cvele_new_account . It's exactly what i wanted.

                                 

                                 

                                Just for others

                                 

                                 

                                 

                                 

                                In JSFF

                                 

                                 

                                 

                                 

                                                                  <af:table value="#{pageFlowScope.SomeBean.list}" var="temp"

                                                                  rows="150"

                                                                  id="dc_t2"

                                                                  selectionListener="#{pageFlowScope.SomeBean.makeCurrent}"

                                                                  rowSelection="single" contentDelivery="immediate"

                                                                  inlineStyle="font-weight:normal;">                                  

                                                                      <af:column id="dc_c5" align="center" clientComponent="true" headerText="header1">

                                                                       <af:outputText value="#{temp.value1}" escape="false"

                                                                                      id="dc_ot5"/>

                                                                      </af:column>

                                       <af:column id="dc_c8" align="center" clientComponent="true" headerText="header2">

                                                                       <af:outputText value="#{temp.value2}" escape="false"

                                                                                      id="dc_ot4"/>

                                                                      </af:column>

                                                                  </af:table>

                                 

                                 

                                 

                                 

                                In BackingBean

                                 

                                 

                                private List<AnotherBean> list = new ArrayList<AnotherBean>();

                                 

                                 

                                //Getter and Setter

                                 

                                 

                                    public void makeCurrent(SelectionEvent selectionEvent){

                                        RichTable table = (RichTable)selectionEvent.getSource();

                                        Object selectedRowData = table.getSelectedRowData();

                                        AnotherBean rowdata = (AnotherBean)selectedRowData;

                                        String value1 = rowdata.getValue1();

                                  String value2 = rowdata.getValue2();

                                    }