0

I am using jsf 2. One part of my code is this:

                <h:panelGrid id="jobDetail" columns="3" cellpadding="7">                        

                    <p:outputLabel value="#{msg['content.jobList.JobName']}" />
                    <p:inputText id="jobName" styleClass="BIC_search_textbox" value="#{timerConfigurationBean.selectedTimerConfigurationJob.jobName}" required="true" requiredMessage="#{msg['content.jobNew.requiredfield.errormsg']}"/>
                    <p:message for="jobName" styleClass="error"/>
                </h:panelGrid>

<p:commandButton id="update" value="Update_Button" action="#{timerConfigurationBean.updateExportJob}" styleClass="bottomButtonsAfterFirst" update="jobDetail" oncomplete="PF('updatejobpopup').show()"/>

This is only a section of the code. What happens is that when I click on the command button "Update_Button" one of the following two things happen:

1) I enter a value in inputText "jobName" and click the command button. First the function in action="#{timerConfigurationBean.updateExportJob}" runs and then the oncomplete="PF('updatejobpopup').show()" runs. This is how it was intended to be so that is okay.

2) I don't enter anything in inputtext (it is a required field), then click on the commandbutton. I see an error message on the webpage next to the Inputtext field (this happens because I have update="jobDetail" in my commandButton) and action="#{timerConfigurationBean.updateExportJob}" is not run however the oncomplete="PF('updatejobpopup').show()" still runs. This is a problem.

I want the oncomplete to only run when there are no errors on the page just like the function in action="#{timerConfigurationBean.updateExportJob}".

Can someone please help.

ITguy
  • 847
  • 2
  • 10
  • 25
  • Possible duplicate of [Keep p:dialog open when a validation error occurs after submit](https://stackoverflow.com/questions/9195756/keep-pdialog-open-when-a-validation-error-occurs-after-submit) – Jasper de Vries May 31 '17 at 08:55

1 Answers1

4

You can use the callback of primefaces to give a feedback to the view. So, in your action method yo can do:

context.addCallbackParam("ok", true);

And in the onComplete:

oncomplete ="if ( args.ok ) { PF('updatejobpopup').show(); }"
David Mantilla
  • 228
  • 1
  • 10
  • Nice one. I did know about custom callback parameters in PrimeFaces :-) In most cases `args.validationFailed` should be enough to work with though. See also: https://stackoverflow.com/questions/9195756/keep-pdialog-open-when-a-validation-error-occurs-after-submit – Jasper de Vries May 31 '17 at 08:57