刚刚解决了壹個细小的技术问题,用 PrimeFaces 4.0 的 UI 组件完成界面元素的开发,XHTML 页面上共有三個按钮,id 分别为 verifyButton、viewButton、downloadButton,其中页面初始化时,verifyButton 处于激活状态(enable),viewButton 和 downloadButton 处于未激活状态(disable),当点击 verifyButton 之后,页面会向后台 Controller 发送 ajax 请求,然后在完成壹些业务逻辑之后返回页面,并将 viewButton 和 downloadButton 激活,此时三個按钮均处于可点击状态。页面部分源代码如下所示:
<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="ver

本文探讨了如何利用PrimeFaces 4.0的<p:commandButton>组件的oncomplete属性,在AJAX请求完成后激活或禁用其他按钮。官方文档解释了oncomplete属性在请求完成后在客户端执行的场景,同时也提到了类似事件如onstart、onsuccess和onerror。了解这些属性可以帮助开发者更精细地控制按钮状态。

373

被折叠的 条评论
为什么被折叠?



