Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primefaces p:dialog doesn't always show up if update="dlg" in commandButton

I have a jsf facelet page like this (extremely simplified version):

    <h:form id="frmAnagPersonName">
        <p:commandButton value="Edit" icon="ui-icon-gear" 
                         update="@form :frmEdit"
                         onsuccess="_dlgEdit.show()"/>
        ...
        <p:dataTable etc...
        ...


    </h:form>

    <p:dialog id="dlgEdit" widgetVar="_dlgEdit" dynamic="true" modal="true" closable="true"
              header="Person Identity">  
        <h:form id="frmEdit" >
            <p:panelGrid id="pnlEdit" columns="2">
                <p:outputLabel id="lblName" for="eName" value="Name"/>
                <p:inputText id="eName" value="#myBean.personName}"
            </p:panelGrid>
        </h:form>
    </p:dialog>  

It works fine, until I put a dynamyc Header in the dialog:

<p:dialog ... header="#{myBean.header}" ...  >  

at which point i have to change the update attribute in the p:commandButton:

update="@form :dlgEdit"  

But in this case the dialog will show up only at the first click on the button. It won't show up the second time, then again show up...
Why? How can I have the dialog show up always?

Thank you

like image 759
yankee Avatar asked Feb 22 '13 16:02

yankee


1 Answers

Use the oncomplete attribute instead of onsuccess attribute.

<p:commandButton ... update="@form :dlgEdit" oncomplete="_dlgEdit.show()" />

The onsuccess attribute is invoked directly when ajax response is successfully arrived but long before the ajax updates are performed based on the ajax response. The oncomplete attribute is invoked when the ajax updates are successfully completed. See also the tag documentation of <p:commandButton>.

Basically, this is the event invocation order:

  • onclick handler is invoked
  • ajax request is prepared with form data based on process
  • onbegin handler is invoked
  • ajax request is sent
  • ajax response is successfully retrieved (HTTP status code is 200)
  • onsuccess handler is invoked
  • ajax updates are performed in HTML DOM based on update
  • oncomplete handler is invoked
like image 61
BalusC Avatar answered Nov 15 '22 10:11

BalusC