我有一个确认消息框,当一个人点击保存按钮时会出现,它只是简单地要求他们确认他们想要保存,然而,即使所有验证都失败了,这也会弹出,有没有办法只在所有验证都成功的情况下显示消息框?
<p>
<p:commandButton value="#{bundle.buttonSaveMark}" icon ="ui-icon-disk" update="displayMark :growl" oncomplete="PF('dlg').show()" />
</p>
<p:dialog header="Confirm Mark" widgetVar="dlg" showEffect="fold" hideEffect="fold">
<h:panelGrid id="displayMark" columns="2" cellpadding="5">
<h:outputText value="Mark to be submitted: " />
<h:outputText value="#{selectedValue}"/>
<p:commandButton id="save"
value="#{bundle.buttonSave}"
actionListener ="#{markingBean.editMark}"
update="Navigation :growl"
icon="ui-icon-disk"
oncomplete="PF('nav').show()"/>
</h:panelGrid>
</p:dialog>
<p:dialog header="Navigation" widgetVar="nav" showEffect="fold" hideEffect="fold">
<h:panelGrid id="Navigation" columns="2" cellpadding="5">
<h:outputText value="Return to this project's marking page: " />
<p:button id="go"
value="#{bundle.buttonProjMark}"
outcome ="/lecturer/marking/marking-index.xhtml?edit_id=#{markingBean.markToEdit.id}"
icon="ui-icon-clipboard"/>
<h:outputText value="Return to staff homepage: " />
<p:button id="staffHome"
value="#{bundle.buttonStaffHome}"
outcome ="/index"
icon="ui-icon-home"/>
</h:panelGrid>
</p:dialog>
那是按钮,然后是确认
您可以使用从Java代码更新导航对话框
RequestContext.getCurrentInstance().update("Navigation");
还添加了一个来自java代码的callBackParam:
RequestContext.getCurrentInstance().addCallbackParam("showDialog",true);
将上述代码添加到您的markingBean.editMark
操作中。如果验证失败,将不会调用您的操作,因此不会添加callbackParam,这样就不会出现对话框。
在客户端应该创建一个js函数来处理请求完成:
function handle(args) {
if (data != null && data.showDialog) {
PF('nav').show()
}
}
在按钮上:
oncomplete="handle(args);"