Displaying a message from managed bean with primefaces confirmation dialog component

有些话、适合烂在心里 提交于 2019-12-30 11:19:09

问题


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


回答1:


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">



回答2:


try this i should works :

<p:commandButton value="Delete" update="testPlanetree" id="deleteBtn" actionListener="#
         {projectTestManagementMB.testFn}"
       disabled="# {projectTestManagementMB.disable}" 

       oncomplete="deleteConfirmation.show()"  />


来源:https://stackoverflow.com/questions/12568162/displaying-a-message-from-managed-bean-with-primefaces-confirmation-dialog-compo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!