使用Primefaces确认对话框组件显示来自托管Bean的消息 [英] Displaying a message from managed bean with primefaces confirmation dialog component

查看:127
本文介绍了使用Primefaces确认对话框组件显示来自托管Bean的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的页面中,我试图单击一个按钮后显示一个确认对话框.在确认对话框中,我使用了属性消息来显示它,单击此按钮后,该消息即为值.所以我做到了:

 <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托管Bean:

    private String deleteConfirmationMsg;//with getters and setters 
    public void testFn(){
       deleteConfirmationMsg="do you want to delete ...";
    }

问题是deleteConfirmationMsg从不采用值您要删除..."(始终为空)

任何想法都会受到赞赏

<p:confirmDialog>已经在第一个HTTP请求上生成了HTML表示,该HTTP请求返回带有表单和对话框的页面.它只是被CSS隐藏,应该由JS显示/隐藏.当您以后使用bean操作方法更改确认消息时,只要您不进行ajax更新,该消息就不会反映在生成的HTML输出中.

因此,为了使更改的消息得到反映,您需要先在客户端更新<p:confirmDialog>的HTML表示,然后再在oncomplete中显示它.为此,可以使用命令按钮的update属性,该属性应显示对话框.

<p:commandButton ... update="confirmDialog testPlanetree">

in my page , i'm trying to display a confirmation dialog after clicking a button .In the confirmation dialog i used the attribute message to display it , this message is taken value after clicking the button . So i did it like that :

 <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 ...";
    }

The problem is that the deleteConfirmationMsg never take the value "do you want to delete ..." (is always empty)

Any idea will be appreciated

解决方案

The <p:confirmDialog> has already generated its HTML representation on the very first HTTP request returning the page with the form and the dialog. It's merely hidden by CSS and is supposed to be shown/hidden by JS. When you change the confirm message afterwards in a bean action method, then it won't be reflected in the generated HTML output as long as you don't ajax-update it.

So, in order to get the changed message being reflected, you'd need to update the HTML representation of the <p:confirmDialog> in the client side before showing it in the oncomplete. You can for this use the update attribute of the command button which should show the dialog.

<p:commandButton ... update="confirmDialog testPlanetree">

这篇关于使用Primefaces确认对话框组件显示来自托管Bean的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆