I have a Primefaces dialog with a form where a user enters some data. After hitting Save, I need the data validated (in the standard JSF way) and if it passes, then some Javascript needs to be called to be able to show an indeterminate progress bar and to hide the form buttons - this is because the action method can take several seconds to complete due to some heavy backend processing.
I know there is args.validationFailed which can be used in an oncomplete but this would only work once the action method has finished which is too late.
At the moment the javascript obviously gets executed when the button is clicked, but i'm unsure how to proceed. Is there any way of kicking off the referPressed function only once validation is passed but before the action method is called?
JSF snippet
<p:commandButton value="Refer" actionListener="#{manageTrickleData.setLogToReferred}"
onclick="referPressed();" update="subview1:mainForm:tabs:tablePanel2
subview1:mainForm:tabs:tablePanel commentMessage" styleClass="dialogButtons">
</p:commandButton>
Javascript
function referPressed() {
$('.dialogButtons').hide();
$('.ui-progressbar-indeterminate').show();
}