title: Intercept a4j:commandButton request
body: <p>I am developing web application using A4J, Richfaces.
  One of my requirement is, I need to check if the user has changed any values in the form when he is trying navigate away from the page.</p>
  
  <p>I have save and cancel buttons in the page.
  I am using <code>a4j:command</code> button for cancel functionality. Clicking on cancel button should do below things</p>
  
  <ol>
  <li>Check if the user has modified anything in the form (this I am doing by using javascript and have a flag if user changed any values)</li>
  <li>Display confirmation box (javascript confirm with values "Do you really want to discard the changes -- YES NO") when user changes form values</li>
  <li>If user says YES, then submit the form using AJAX (by using A4J)</li>
  </ol>
  
  <p>My a4j command button code is like this</p>
  
  <pre><code>&lt;a4j:commandButton action="MyClass.cancel_action"
      onclick="checkIsPageChanged()"/&gt;
  </code></pre>
  
  <p>The issue here is, while using using <code>a4j:commandButton</code>, I cannot call the intermediate javascript function (the function which checks if user has updated any values and displays confirmation box) and then submit the request using ajax.
  I have looked at the code generated by JSF and the code is like (not the exact but syntact)</p>
  
  <pre><code>&lt;input type="button"
      onclick="checkIsPageChanged();AJAX.submit('')/&gt;
  </code></pre>
  
  <p>The thing is when I click on button, it is calling only <code>checkIsPageChanged()</code> and not calling <code>AJAX.submit()</code>.</p>
  
  <p>Any workaround for this will help me.</p>
  
  <p>Thank you in advance.</p>