Primefaces how to update content in a dialog and keep the dialog centered?

前端 未结 2 950
天命终不由人
天命终不由人 2021-02-01 20:29

I have a dialog that contains no content on page load and I\'m dynamically setting the content of a dialog box based on the link that a user clicks on.



        
相关标签:
2条回答
  • 2021-02-01 21:08

    The onclick is executed before the ajax request. You need to open the dialog in oncomplete instead. This will be executed after the ajax request and update. The <p:dialog> is namely by default hidden unless its visible attribute evaluates true.

    <p:commandLink value="Read more" actionListener="#{content.getFullArticle}" 
        update=":dialog" oncomplete="dlg.show()">
    

    Unrelated to the concrete problem, are you aware that you can pass fullworthy objects as method arguments since EL 2.2? This makes the <f:attribute> and actionListener "hack" superfluous:

    <p:commandLink value="Read more" action="#{content.getFullArticle(news)}" 
        update=":dialog" oncomplete="dlg.show()" />
    
    0 讨论(0)
  • 2021-02-01 21:22

    I had the same problem. Updating the dialog makes it disappear and reappear (and forget its position).

    To solve it, I created a wrapper tag around the dialog content.

    <p:commandLink update=":playerViewDialogHeader,:playerViewDialogContent"
                   oncomplete='playerViewDialogJS.show()' value='#{item.name}' />
    
    
    <p:dialog id='playerViewDialog' widgetVar='playerViewDialogJS'>
    
       <f:facet name="header">
          <h:outputText id="playerViewDialogHeader" value="#{playerController.objectView.name}" />
       </f:facet>
    
       <h:form id='playerViewDialogContent'>
          <!-- CONTENT GOES HERE -->
       </h:form>
    
    </p:dialog>
    
    0 讨论(0)
提交回复
热议问题