0

My command Button checks of required inputs properlly if i put ajax="false" but it doesn't fire the onstart and the oncomplete. However, when i put ajax="true" every things work fine if the validation success but if i didn't enter a valid input nothing is fired.

 <p:commandButton   value="Extract" style="width: 12%;height: 100%" update="tableemails, :confirmPurchase, :confirmPurchaseTest, :mainform" id="extractbutton" widgetVar="ButtonExtract"
                                   actionListener="#{mailMB.searchEmails()}" ajax="false" 
                                   icon="ui-icon-disk" styleClass="ui-priority-primary" 
                                   onstart="blockUIWidget1.show();" oncomplete=" blockUIWidget1.hide(); freeMails();" />   

How can i fix this to make my Button checks the validation and fire onstart and oncomplete properly???

junior developper
  • 448
  • 2
  • 19
  • 40

1 Answers1

0

Defining the button as ajax="false" won't give you some of the features that are only available through a ajax requests (ie. onstart, oncomplete, update).

I will assume that by "checks of required inputs properlly" you are trying to say that messages are displayed detailing the validation problems. If that is the case check if your messages component is being auto updated as in this example:

<p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" /> 

If it's not, tell messages to auto update or include its id in your buttons update property:

<p:commandButton   value="Extract" style="width: 12%;height: 100%" update="messages, tableemails, :confirmPurchase, :confirmPurchaseTest, :mainform" id="extractbutton" widgetVar="ButtonExtract"
                   actionListener="#{mailMB.searchEmails()}"  
                   icon="ui-icon-disk" styleClass="ui-priority-primary" 
                   onstart="blockUIWidget1.show();" oncomplete=" blockUIWidget1.hide(); freeMails();" />   
  • with your suggestion i get the validation messages but i also get the dialog shown by the oncomplete even if the validation failed which is not what am looking for. – junior developper Feb 17 '14 at 12:55
  • That you can be done by checking **args.validationFailed**. Consider something like `if (!args.validationFailed) {freeMails();}`. Take a look at this http://stackoverflow.com/questions/9195756/keep-pdialog-up-when-a-validation-error-occurs-after-submit – Daniel Teleginski Camargo Feb 17 '14 at 13:05
  • With oncomplete="if (#{not facesContext.validationFailed}) freeMails.show();" i get the dialog shown even when validation failed what's the cause – junior developper Feb 17 '14 at 13:34
  • I still think you should use only this part: if ( !args.validationFailed ) {freeMails();} – Daniel Teleginski Camargo Feb 17 '14 at 14:07
  • It works for the first submit but if enter valid inputs and submit another time it clears the form and the method in the action listener is not invoked – junior developper Feb 17 '14 at 14:39