2 Replies Latest reply on Sep 18, 2008 5:08 PM by edlin

    Action On RowClick

    leesy

      Hi,


      I was just wondering if it's possible to fire an action in my backing bean when a row in a DataTable is clicked.  For example, here's my table as it stands:


      <rich:dataTable id="templateFields" var="t" value="#{viewTemplate.results}" cellpadding="0" onRowClick="toggleSelectedRow(this)" >
           <h:column>
                <!-- Various columns to show data -->
           </h:column>
      
           <h:column>
                <f:facet name="header">
                     Actions
                </f:facet>
                <h:commandLink action="#{templateHome.select(t)}">
                     Select
                </h:commandLink>
           </h:column>
      </rich:dataTable>



      I've got an onRowClick event that fires off a JavaScript action that indicates a row as selected.  I've also got a select action that marks this item as selected in the backing bean.


      But is there anyway of combining the two?  I want my action to be called on the onRowClick (and hopefully the Javascript as well).


      Cheers for any help,
      Lee

        • 1. Re: Action On RowClick
          triantafyllos

          Hi,
          I am not sure if this is the best solution, but I tried it and it works fine for me!
          In the XHTML code:



          <rich:dataTable id="tourstationen" value="#{backingbean.list}"
          var="place" rows="5" rowKeyVar="rkv" >
          <a4j:support event="onRowClick" actionListener="#{backingbean.selectionChanged}" />





          In the Backing bean I implemented following method:


              public void selectionChanged(ActionEvent event) {
                  UIComponent comp = event.getComponent();
                  Object obj = comp.getParent();
                  if (obj instanceof HtmlDataTable) {
                          HtmlDataTable table = (HtmlDataTable) obj;
                          Object rowData = table.getRowData();
                          if (rowData instanceof MyObject) {
                                  MyObject selObj = (MyObject) rowData;
                                          setSelectedObject(selObj );                             
                                  }                       
                          }
              }




          Cheers,
          trian
               

          • 2. Re: Action On RowClick
            edlin

            I had a similar issue perhaps, I thought having a onRowClick in my rich:dataTable was blocking the a4j:support event.
            It was, but the answer was to include a return true; at the end of my javascript function.


            So, make sure your toggleSelectedRow(this) is returning true.


            Also you can take the javascript out of the rich:dataTable and move it to the a4j:support.



             <a4j:support event="onRowClick"
                          onsubmit="toggleSelectedRow(this)"
                          actionListener="#{someBean.onSelectionChange}"/>
            



            I tried on oncomplete, but then it only highlights the cell (the TD).