我有一个功能,我必须通过我的确认对话框调用我的管理bean,这是删除按钮。当用户单击删除按钮时,会弹出一个确认对话框,并且应该调用"Yes"的onclick
,我的相关管理bean。但是我做不到。
<p:commandButton id="Delete" action="#{tbeanId.delete}" icon="ui-icon ui-icon-trash"
value="Delete" title="GDeleteButton" ajax="false" onclick="PF('groupDeleteConfirm').show();" type="button">
<p:confirm header="Delete Record" message="Are you sure about deleting this record?" icon="ui-icon-alert"/>
</p:commandButton>
<p:confirmDialog global="true" showEffect="fade" hideEffect="explode" widgetVar="groupDeleteConfirm">
<p:commandButton title="GDelYesButton" value="Yes" oncomplete="PF('groupDeleteConfirm').hide()" " />
<p:commandButton title="GDelNoButton" value="No" onclick="PF('groupDeleteConfirm').hide()" type="button" />
</p:confirmDialog>
当您使用p:confirmDialog
与global="true"
的确认/取消按钮(有些不直观)由这2个样式类识别:
styleClass="ui-confirmdialog-yes"
styleClass="ui-confirmdialog-no"
然后动作将被调用,show()/hide()将自动发生。Ajax应该在主按钮上是真实的,你不需要type="button"
,所以总而言之,它会简单得多:
<p:commandButton id="delete"
action="#{trafficExpenseItemsMBean.deleteExpenseItemsGroup}"
icon="ui-icon ui-icon-trash"
value="Delete"
title="GDeleteButton">
<p:confirm header="Delete Record"
message="Are you sure about deleting this record?"
icon="ui-icon-alert"/>
</p:commandButton>
<p:confirmDialog global="true" showEffect="fade" hideEffect="explode">
<p:commandButton title="GDelYesButton" value="Yes" styleClass="ui-confirmdialog-yes"/>
<p:commandButton title="GDelNoButton" value="No" styleClass="ui-confirmdialog-no" />
</p:confirmDialog>
另一个选择是使其非全局的。然后,您需要将操作移动到yes按钮,并将消息移动到
中的p:confirmDialog中。<p:commandButton id="delete"
icon="ui-icon ui-icon-trash"
value="Delete"
title="GDeleteButton"
onclick="PF('groupDeleteConfirm').show()">
</p:commandButton>
<p:confirmDialog message="Are you sure about deleting this record?"
showEffect="fade"
hideEffect="explode"
widgetVar="groupDeleteConfirm">
<p:commandButton title="GDelYesButton"
value="Yes"
action="#{trafficExpenseItemsMBean.deleteExpenseItemsGroup}"
oncomplete="PF('groupDeleteConfirm').hide()"
update=":growl"/>
<p:commandButton title="GDelNoButton"
value="No"
oncomplete="PF('groupDeleteConfirm').hide()"/>
</p:confirmDialog>
我不确定你是否真的想要那些按钮上的title
,因为它们是显示给用户的。
当你使用p:commandButton
的动作需要在服务器上完成时,你不能使用type="button"
,因为这是按钮,用于执行自定义javascript而不引起ajax/非ajax请求到服务器。
为此,您可以省略type属性(默认值是"submit"),或者您可以显式使用type="submit"
。
希望这将帮助某人!