【问题标题】:Displaying a message from managed bean with primefaces confirmation dialog component使用 primefaces 确认对话框组件显示来自托管 bean 的消息
【发布时间】:2012-09-24 15:29:47
【问题描述】:

在我的页面中,我试图在单击按钮后显示一个确认对话框。在确认对话框中,我使用属性消息来显示它,该消息在单击按钮后被取值。所以我就这样做了:

 <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 从来没有取值“你想删除...”(总是空的)

任何想法将不胜感激

【问题讨论】:

  • 确保你的 setter 和 'setDeleteConfirmationMsg' 完全一样,区分大小写
  • @D3mon:为什么错误的 setter 名称会导致这个问题?更重要的是,在这种情况下,setter 实际上是强制性的吗?

标签: jsf-2 xhtml primefaces


【解决方案1】:

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

因此,为了反映更改后的消息,您需要先在客户端更新 &lt;p:confirmDialog&gt; 的 HTML 表示,然后再将其显示在 oncomplete 中。为此,您可以使用应该显示对话框的命令按钮的update 属性。

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

【讨论】:

    【解决方案2】:

    试试这个我应该可以工作:

    <p:commandButton value="Delete" update="testPlanetree" id="deleteBtn" actionListener="#
             {projectTestManagementMB.testFn}"
           disabled="# {projectTestManagementMB.disable}" 
    
           oncomplete="deleteConfirmation.show()"  />
    

    【讨论】:

    • 这究竟是如何回答这个问题的?您没有以任何方式具体解释/描述解决方案。您只展示了一段与 OP 的代码最相似的代码,唯一的变化是您使用了actionListener 而不是action。为什么您认为这可以解决 OP 的具体问题?为什么您没有以任何方式解释解决方案,我们是否必须根据比较代码来猜测它?对这个不清楚的答案投赞成票的人应该重新考虑投赞成票。
    猜你喜欢
    • 1970-01-01
    • 2021-12-12
    • 2015-05-08
    • 1970-01-01
    • 2011-08-15
    • 2013-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多