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

    Action On RowClick

    Lee Theobald Newbie


      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)" >
                <!-- Various columns to show data -->
                <f:facet name="header">
                <h:commandLink action="#{templateHome.select(t)}">

      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,

        • 1. Re: Action On RowClick
          Triantafyllos Kirtzakis Newbie

          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 );                             


          • 2. Re: Action On RowClick
            Adrian I Newbie

            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"

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