Search code examples
ajaxjsfjsf-2primefacescommandbutton

oncomplete of p:commandButton not firing within ui:composition


The following code appears in a ui:composition page and uses a template, the template inserts this page using ui:insert.

        <p:commandButton id="basic" value="Contact #{viewProfileView.profile.credentials.username}" onclick="PF('dlg1').show();" type="button" />

    <h:form id="createMail">
        <p:dialog id="createMailDialog" header="Contact #{viewProfileView.profile.credentials.username}" widgetVar="dlg1" modal="true" draggable="false">
            <p:growl id="growl"/>

            <p:inputTextarea value="#{viewProfileView.emailBody}"
                             rows="5" cols="80" maxlength="399"
                             counter="charsLeft" 
                             counterTemplate=" {0} chars remaining."
                             autoResize="false" />
            <h:outputText id="charsLeft" />

            <p:commandButton id="sendMailButton" value="Send"
                             action="#{viewProfileView.sendMail}"
                             update="growl"
                             oncomplete="PF('dlg1').hide();"/>
        </p:dialog>
    </h:form>

I'm using latest JSF and Primefaces 5.1.

Everything works fine except for the oncomplete of the 'sendMailButton' commandButton fails to be called to close the dialog. I know this code works as I have put it in a page of its own and seen it working, it just doesnt want to work as part of a ui:composition with template.

Help would be most appreciated as i've been searching for an answer without luck.

UPDATE: If I change 'oncomplete' to 'onsuccess' it works, but only once, however this does not resolve my issue.

Many thanks.


Solution

  • It appears that it was the template that was causing problems. Working now.