在我的页面中,我试图在单击按钮后显示确认对话框。在确认对话框中我使用属性消息显示它,单击按钮后该消息被取值。所以我这样做了:
<p:commandButton value="Delete" update="testPlanetree" id="deleteBtn"
disabled="#{projectTestManagementMB.disable}" oncomplete="deleteConfirmation.show()"
action="#{projectTestManagementMB.testFn}"/>
<p:confirmDialog id="confirmDialog" message="#
{projectTestManagementMB.deleteConfirmationMsg}"
header="Confirming Deleting Process" severity="alert"
widgetVar="deleteConfirmation">
<p:commandButton id="confirm" value="Yes Sure" update="messages"
oncomplete="deleteConfirmation.hide()" />
<p:commandButton id="decline" value="Not Yet"
onclick="deleteConfirmation.hide()" type="button" />
</p:confirmDialog>
ProjectTestManagementMB Managed Bean:
private String deleteConfirmationMsg;//with getters and setters
public void testFn(){
deleteConfirmationMsg="do you want to delete ...";
}
问题是deleteConfirmationMsg
永远不会取值“你想要删除......”(总是空的)
任何想法都将受到赞赏
答案 0 :(得分:7)
<p:confirmDialog>
已经在第一个HTTP请求上生成了HTML表示,返回带有表单和对话框的页面。它只是被CSS隐藏,应该由JS显示/隐藏。当您在bean操作方法中更改确认消息后,只要您不进行ajax更新,它就不会反映在生成的HTML输出中。
因此,为了反映更改后的消息,您需要在<p:confirmDialog>
中显示oncomplete
之前更新客户端update
的HTML表示形式。您可以使用命令按钮的<p:commandButton ... update="confirmDialog testPlanetree">
属性来显示对话框。
{{1}}
答案 1 :(得分:1)
尝试这个我应该工作:
<p:commandButton value="Delete" update="testPlanetree" id="deleteBtn" actionListener="#
{projectTestManagementMB.testFn}"
disabled="# {projectTestManagementMB.disable}"
oncomplete="deleteConfirmation.show()" />