3 Replies Latest reply on Apr 18, 2013 3:13 AM by Vadim Poretsky

    rich:extendedDataTable select row from bean without ExtendedTableModel

    Vadim Poretsky Newbie

      Hello!

      I'm trying to select rows from my bean using selection property of rich:extendedDataTable. Unfortunately without success. 

      The only difference I can find between demos and my app is that I'm using ResultSetDataModel. So I don't have rowKey property in my datamodel. However selection property is working okay and contains rowIndex values of my extendedDataTable.

      From my bean I'm trying to do something like this:

       

       

      {code:java}

      private Collection<Object> selection;

       

          public void selectFirstRow() {

              selectRow(Integer.valueOf( (getPage()-1) * pageSize));

          }

       

          public void selectRow(Object row) {

              if (getSelection()==null){

                  Collection<Object> s = new HashSet<Object>();

                  s.add(row);

                  setSelection(s);

              }else{

                  getSelection().clear();

                  getSelection().add(row);

              }

          }

      {code}

       

      And here is command button with a table somewhere

       

      {code:xml}

      <a4j:commandButton render="main_table1" id="selectFirstRow" action="#{bean.selectFirstRow}" value="select first row"/>

      ...

      <rich:extendedDataTable  id="main_table1" value="#{bean.items}" var="row"

                                                  rows="#{bean.pageSize}" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" style="border:solid 1px"

                                                  selection="#{bean.selection}">

      {code}

       

      Is it possible to select row from bean in that way?

        • 1. Re: rich:extendedDataTable select row from bean without ExtendedTableModel
          Amstrong Huang Newbie

          try this:

           

          <rich:extendedDataTable selectionMode="single"

                                          selection="#{clienteDM.selection}" id="resultTable"

                                          value="#{clienteController.clienteDataModel}" var="cliente"

                                          rows="#{generalController.getFilasTablas('CLIENTES')}"

                                          styleClass="widthSearchTable"

                                          noDataLabel="#{msg.msj_tabla_vacia}">

                                          <a4j:ajax event="selectionchange"

                                              listener="#{clienteController.selectionListener}"

                                              render="contentPanel, resultTable" />

          ...

          </rich:extendedDataTable>

           

          public void selectionListener(final AjaxBehaviorEvent event) {

              UIExtendedDataTable dataTable = (UIExtendedDataTable) event

                      .getComponent();

              Object originalKey = dataTable.getRowKey();

               //We always have only 1 object on clienteDM.getSelection

              for (Object selectionKey : clienteDM.getSelection()) {

                  dataTable.setRowKey(selectionKey);

                  if (dataTable.isRowAvailable()) {

                    //Do your logic here with

                    (Client) dataTable.getRowData();

                    }

              }

               //Clean the selection

              clienteDM.setSelection(null);

              dataTable.setRowKey(originalKey);

          }

           

          Hope it works for you... as soon as client selects one row from the datatable the selectionListener is fired with <a4j:ajax event="selectionchange" ... >

          • 2. Re: rich:extendedDataTable select row from bean without ExtendedTableModel
            Vadim Poretsky Newbie

            Thanks for your response but I have no problems selecting rows from a client (using selectionListener). I have difficulties selecting rows from a bean in way client could "see" selection changes. And I showed an example trying to change selection attribute from a bean hoping it will have effect on a client. Without success...

            • 3. Re: rich:extendedDataTable select row from bean without ExtendedTableModel
              Vadim Poretsky Newbie

              Solved!

              It is useful to use sometimes source debugging. Here is right code snippet for server side row selection:

               

               

              {code:java}

               

                  public void selectRow(Object row) {

                      if (getSelection()==null){

                          Collection<Object> s = new HashSet<Object>();

                          s.add(row);

                          setSelection(s);

                      }else{

                          getSelection().clear();

                          getSelection().add(row);

                      }

                     

                      UIExtendedDataTable table = (UIExtendedDataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent("main_form1:main_table1");

                      table.getAttributes().put("activeRowKey", row);

                      //table.setRowKey(row);

                    

                  } 

               

               

              {code}