<h:form id="verificationForm"> <div class="button-padding right mt10"> <p:commandButton id="verifyButton" value="校验" update="@this" widgetVar="verifyButton" disabled="#{!batchVerificationMB.enabledVerifyButton()}" process="@this batchVerificationTable" actionListener="#{batchVerificationMB.verify()}" oncomplete="validationUtil.handleAjaxResponse(args, displayErrorMessagesBathVerification, function(){displayVerifyMessage();viewButton.enable();downloadButton.enable();})" /> <p:commandButton id="viewButton" value="查看" process="@this" widgetVar="viewButton" update=":verificationResultForm" onclick="verificationResultDialog.show();" /> <p:commandButton id="downloadButton" value="导出" process="@this" widgetVar="downloadButton" ajax="false" onclick="PrimeFaces.monitorDownload(start, stop)" icon="ui-icon-arrowthichk-s"> <p:fileDownload value="#{fileDownloadController.file}" /> </p:commandButton> <script type="text/javascript"> viewButton.disable(); downloadButton.disable(); </script> </div> </h:form> <h:form id="verificationResultForm"> //...此处省略部分代码 </h:form> <p:dialog widgetVar="verificationResultDialog" modal="true" closable="true" resizable="false" width="800"> //...此处省略部分代码 </p:dialog>其实只有两個地方需要注意,分别列举如下:
validationUtil.handleAjaxResponse( args, displayErrorMessagesBathVerification, function(){ //显示后台反馈的信息 displayVerifyMessage(); //将viewButton和downloadButton状态激活 viewButton.enable(); downloadButton.enable(); } )
其实说起来,PrimeFaces 4.0 的 <p:commandButton> 用起来并不复杂,只是自己还不熟悉其用法罢了。查看 PrimeFaces 4.0 官方文档是,它是这样介绍 oncomplete 属性的: 默认值为null,类型为String,当ajax请求完成之后客户端会回调属性oncomplete指定的内容。其实已经说的非常简单明了了。类似的事件属性还有 onstart、onsuccess、onerror 等,如果有兴趣的朋友可以自行查找 相关文档以了解更多细节。