4 Replies Latest reply on Nov 13, 2007 1:32 AM by richuser

    dataTable onRowClick and commandLink inside work together?

    j-pro

      Good afternoon.

      I've found out that if I use both of a4j:support for onRowClick in dataTable and a4j:commandLink in this dataTable, it works together. I mean if I click on the commandLink, I get fired and onRowClick too. Is there any way to avoid it? Because if I use reRender in both of a4j:commandLink and a4j:support, the specified region reRenders twice. Can I avoid it somehow?

      Here is my snapshot:

      <h:form id="employeesDataTable_form">
       <rich:dataTable style="width:167px"
       id="employeesDataTable"
       binding="#{anketaDTableMan.dataTable}"
       rows="20"
       columnsWidth="98%,1%,1%"
       onRowMouseOver="this.style.backgroundColor='#B5CEFD'"
       onRowMouseOut="this.style.backgroundColor='#{org.richfaces.SKIN.tableBackgroundColor}'"
       cellpadding="0" cellspacing="0" value="#{amBean.employeeListMan.employees}"
       var="item">
      
       <a4j:support event="onRowClick" onSubmit="this.style.backgroundColor='#000000" actionListener="#{anketaDTableMan.dtRowSelected}"/>
      
       <f:facet name="header">
       <rich:columnGroup>
       <rich:column>
       <h:outputText value="Numele" />
       </rich:column>
       <rich:column>
       <rich:spacer />
       </rich:column>
       <rich:column>
       <rich:spacer />
       </rich:column>
       </rich:columnGroup>
       </f:facet>
      
       <rich:column style="">
       <h:outputText value="#{item.lastName}" />
       </rich:column>
      
       <rich:column style="">
       <a4j:commandLink id = "delLink" value = "X" styleClass="txtlink"
       onclick="if (!confirm('Are you sure?') ) {return false;}"
       action = "#{amBean.actDeleteFakeEmployee}" reRender = "employeesDataTable">
       <a4j:actionparam value="#{item.employeeId}" name="employeeId"
       assignTo="#{amBean.parameterID}"/>
       </a4j:commandLink>
       </rich:column>
      
       </rich:dataTable>
       <rich:spacer height="20"/>
       <rich:datascroller for="employeesDataTable" maxPages="3"/>
       </h:form>


      Thanks in advance.

        • 1. Re: dataTable onRowClick and commandLink inside work togethe
          dmitry.demyankov

          It seems that actionListener on event="onRowClick" is fired event if you select 'cancel' in the confirmation dialog.. I'd suggest you to set some flag when delete method is called and then check in actionListener if this flag was set. Can't think of a better solution so far..

          • 2. Re: dataTable onRowClick and commandLink inside work togethe
            j-pro

             

            "dmitry.demyankov" wrote:
            event if you select 'cancel' in the confirmation dialog..

            Yes, that's why I wrote here. Actually it's logical, but very uncomfortable.


            "dmitry.demyankov" wrote:
            I'd suggest you to set some flag when delete method is called and then check in actionListener if this flag was set. Can't think of a better solution so far..

            Yes, but what if user presses Cancel? The delete method will not be called, so the flag will not be set...

            The one solution that comes into my mind is to use a4j:actionparam with a4j:commandLink. But is there any other ways?

            • 3. Re: dataTable onRowClick and commandLink inside work togethe
              j-pro

              To not just close the question, I'll post here the solution, which was gave to me by Maksim Kaszynski: to prevent execution of onrowclick event handler after clicking on a commandLink in a table row, you should add in commandLink: "onclick="Event.stop(event||window.event);""

              In my case it would be:

              <a4j:commandLink id = "delLink" value = "X" styleClass="txtlink"
               onclick="Event.stop(event||window.event); if (!confirm('Are you sure?') ) {return false;}"
               action = "#{amBean.actDeleteFakeEmployee}" reRender = "employeesDataTable">
               <a4j:actionparam value="#{item.employeeId}" name="employeeId"
               assignTo="#{amBean.parameterID}"/>
              </a4j:commandLink>


              And I should admit that it works perfect. Thanks, Maksim!

              • 4. Re: dataTable onRowClick and commandLink inside work togethe
                richuser

                Hi J-Pro,

                Is there a way to prevent execution of onrowclick event completely?

                I have a scrollabledatatable and when I click on a row, and then click on a sortable header, I get this error:

                java.io.NotSerializableException: org.richfaces.model.selection.SelectionRange