简体   繁体   中英

p commandbutton action does not fire but oncomplete fires

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.

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(); }"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM