5

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

yankee
  • 509
  • 2
  • 9
  • 18
  • What version of PF is this? try setting `appendToBody="true"` on your dialog. Also observe the difference in the state of the DOM when the dialog shows up Vs when it doesn't – kolossus Feb 22 '13 at 16:58
  • Also take note of the condition on which the dialog shows up: OnSuccess. What blocks that success? – kolossus Feb 22 '13 at 17:01
  • I use PrimeFaces 3.5. `appendToBody`has no effect. Both `oncomplete` and `onsuccess` are called (I tried with JS `alert()`). How can I observe the state of the DOM? (sorry for my ignorance ;-)) – yankee Feb 22 '13 at 17:32

1 Answers1

11

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
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I would just add that my opinion is that `dynamic="true"` in this example doesn't have any sense, as dialog is already completely updated after AJAX request, so in AJAX response there would be whole dialog, and another AJAX request will be made to load dialog dynamically. – partlov Feb 22 '13 at 17:12
  • @partlov: Yes indeed, that attribute can be omitted. However, it's useful if you have relatively large content in the dialog and would like to not immediately load it on initial request, but only when dialog is opened for 1st time. – BalusC Feb 22 '13 at 17:13
  • I don't know exactly how would Primefaces act here, but if dynamic dialog is completely updated, it is maybe in state "not loaded", as it is initially loaded. So AJAX loading of dialog will be fired again? Maybe I'm wrong but I'm not in situation to check this right now. – partlov Feb 22 '13 at 17:18
  • 2
    @partlov: the `show()` implicitly triggers dynamic loading, but when used in `onsuccess` it will later be overridden when the `update` takes place with content from "one step behind". – BalusC Feb 22 '13 at 17:22
  • @BalusC Yeah!! Thank you so much!!!! I tried to show an alert on the two events, but I didn't try to move `_dlgEdit.show()` to `oncomplete`. Me stupid. @partlov `dynamic="true"` is for the real case, much complex and "dynamic" than my example here. Btw, it's always useful to know these details. Thank you – yankee Feb 22 '13 at 17:48