2 Replies Latest reply on Jul 31, 2007 12:35 PM by Yannick Lazzari

    a4j:support onsubmit : prevent AJAX request without returnin

    Yannick Lazzari Newbie

      Hi,

      I would like to know if someone found an elegant way to prevent an AJAX request from being fired on an "onsubmit" of a a4j:support without actually returning false?

      Let me explain. Assume the following template:

      <rich:dataTable value="#{someList}" var="item" ajaxKeys="#{ajaxKeys}>
       <a4j:support event="onRowClick" onsubmit="if (preventOnClick()) {return false;}" action="#{someAction}" reRender="col1, col2"/>
       <rich:columnGroup>
       <rich:column>
       <f:facet name="header">Column 1</f:facet>
       <h:inputHidden value="#{item.editFlag}"/>
       <h:outputText value="#{item.column1}"/>
       </rich:column>
       <rich:column>
       <f:facet name="header">Column 2</f:facet>
       <h:panelGroup id="col2">
       <h:outputText value="#{item.column2}" rendered="#{not item.editFlag}"/>
       <h:selectBooleanCheckbox value="#{item.column2}" rendered="#{item.editFlag}"/>
       </h:panelGroup>
       </rich:column>
       </rich:columnGroup>
      </rich:dataTable>
      


      Here, I want to edit a column of a table when I click on the row; so I have a a4j:support for the "onRowClick" event on my whole table. The problem is that since this generates an "onclick" on each "tr" tag, the AJAX request fires on every click inside that row, even when I'm trying to check/uncheck the value of the checkbox. So I figured I would do something to prevent the "onclick" event from happening when I know I've already clicked on the row to edit the column (the "preventOnClick" javascript method). The problem is that if the "onclick" event on the row returns false, it also cancels the checking/unchecking of the checkbox. Would anyone have a solution for that?

      I was about to override the javascript of Ajax4jsf (the A4J.AJAX.Submit method) to look for some global flag to know if it should execute the request or not and get rid of the "return false" statement on the"onsubmit" of the a4j:support. I think there's a difference between not wanting to execute the AJAX request and preventing the "onclick" event from doing anything. Right now, there's no way to make the difference.

      Thanks for your help.