p:commandButton 操作在 p:confirmDialog 中不起作用 [英] p:commandButton action not working in p:confirmDialog
问题描述
我有一个功能,我必须通过用于删除按钮的确认对话框调用我的托管 bean.当用户单击删除按钮时,会弹出一个确认对话框,并且应该调用是"的 onclick
我的相关托管 bean.但是我做不到.
I have a functionality where I have to call my managed bean through my confirmation dialog box which is for delete button. When the user clicks on delete button there is a confirmation dialog box that pops up and onclick
of "Yes" my relative managed bean should get called. But I am not able to do it.
<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 个 styleClasses 标识:
When you use the p:confirmDialog
with global="true"
the confirm/cancel buttons are (somewhat unintuitively) identified by these 2 styleClasses:
styleClass="ui-confirmdialog-yes"
styleClass="ui-confirmdialog-no"
然后该动作将被调用并且 show()/hide() 将自动发生.主按钮上的 Ajax 应该是真的,你不需要 type="button"
所以总而言之它会简单得多:
Then the action will be called and show()/hide() will happen automatically. Ajax should be true on the main button and you don't need type="button"
so all in all it will be much simpler:
<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>
另一种选择是使其成为非全局的.然后,您需要将操作移至是按钮并将消息移至 p:confirmDialog,如
Another option would be to make it non-global. Then you'd need to move the action to the yes-button and the message to the p:confirmDialog as in
<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
,因为它们会显示给用户.
I'm not sure you really want those title
's on the buttons though, as they are shown to the user.
这篇关于p:commandButton 操作在 p:confirmDialog 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!