3 Replies Latest reply on Feb 6, 2008 8:12 AM by E Aish

    How to find out, which Row was clicked in a DataTable?

    Hans Maulwurf Newbie

      Well, a simple (?) Thing: I want a DataTable and dependend on what Row I click, another DataTable should be reRendert with new Datas.
      But: How can I find out, which Row was clicked?


      JSF-Code:

      <rich:dataTable>
      <a4j:support event="onRowClick" ajaxSingle="true" reRender="anotherTable" actionListener="#{myBean.selectRow}" />
      ...
      </rich:dataTable>


      Java-Code:

      ...
      public void selectRow(ActionEvent ae){
      // What can I do here???
      }
      ...


        • 1. Re: How to find out, which Row was clicked in a DataTable?
          Lotfi Mellouk Master

          helloo

          I do something like this:

          <rich:dataTable cellpadding="0" cellspacing="0" border="0" var="list" ..>
          <a4j:support event="onRowDblClick" reRender="details"
           action="#{queryManager.getSelected}"
           oncomplete="javascript:Richfaces.showModalPanel('_panel',{left:'auto', top:'auto'})" />
          
          

          <a4j:support event="onRowDblClick"
          action="#{bean.getSelectedRow}" />
          
          <rich:column>
          </rich:column>
          
          

          on the backing bean action

          MyBean bean = (MyBean) FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("list");





          • 3. Re: How to find out, which Row was clicked in a DataTable?
            E Aish Novice

            Hi,

            I have a similar situation. I have to display the list of rows from a table using dataTable. I am also using dataScroller to provide pagination option as there is a long list of rows and pagination would be easier.

            Depending on the row selected from the above table, the second table should be displayed.

            My code is as follows:

            <rich:dataTable value="#{TableDetail.dissummarytbl}"
            var="category" rowKeyVar="rkv" rowkey="#{rowkey}"
            onRowClick="RowClick()" rows="5" binding="#{TableDetail.hseldataTable}">

            <rich:column>

            </rich:column>
            .
            .
            .

            <rich:datascroller pageIndexVar="1" pagesVar="5">
            </rich:datascroller>

            </rich:dataTable>

            Hidden commandButton to trigger row selection with the help of JS
            ==============================
            <a4j:commandButton id="cmdButton" value=" " reRender="table" style="width:0px;height:0px"
            action="#{TableDetail.takeSelection}" immediate="true">

            This is the second table
            ================
            <rich:dataTable value="#{TableDetail.selectedRecDetails}" var="sel" id="table">
            </rich:dataTable>



            The takeSelection method in my backing bean is as follows:

            public void takeSelection()
            {
            Object rowdata = this.getHseldataTable().getRowData();
            this.selectedRecs.add((Summary) rowdata);
            }

            == private HtmlDataTable hseldataTable; (There is a getter and setter for this hseldataTable)

            The takeSelection method is not working. It is throwing illegalArguementException and not working.

            Can you please pass on your suggestions?

            Your help is greatly appreciated as I am new to JSF and developing my first JSF application.

            Thanks
            Aish