Search code examples
formsjsf-2primefacesconfirm-dialog

Primefaces v.5.3.5 confirm dialog render issue outside main h:form and inside main form is rendered but it is not working properly


I am using PF v.5.3.5 and JSF v.2.2.8. It is a frequent topic in SO. I noticed that there is a bug in PF v.5.3.5 documentation related to the appendTo attribute.

1st approach

The p:confirmDialog is rendered and commandbuttons are rendered but actions does not work and message is not rendered if it is placed inside of nested h:form.

2st approach

If I place this dialog outside of main h:form it is not rendered at all also if I add the global="true" attribute.

3st approach

The p:confirmDialog is rendered and commandbuttons are rendered but actions does not work and message is rendered if the nested h:form is removed.

<h:form>
...
                <p:confirmDialog id="askSessionDialog1" widgetVar="askSessionDialog1" severity="alert"
                                 appendTo="@(body)" rendered="#{treeData.askSessionDialogRendered}" visible="#{treeData.askSessionDialogRendered}">
                    <h:form>
                    <f:facet name="message">
                        <h:outputText value="#{msg.WEB_ADMIN_PAGES_TREESEGMENT_NOSESSION}" escape="false"/>
                    </f:facet>

                        <p:commandButton value="#{msg.WEB_BUTTONS_OK}" action="#{treeData.save(false, true)}" icon="fa fa-check"
                                         update="@(form)" type="button" />
                        <p:commandButton value="#{msg.WEB_BUTTONS_CANCEL}" action="#{treeData.setAskSessionDialogRendered(false)}"
                                         icon="fa fa-close" onclick="PF('askSessionDialog1.hide()')" update="@(form)" type="reset" />
                    </h:form>
                </p:confirmDialog>
...
</h:form>

BECKEND PART

setAskSessionDialogRendered(true);
RequestContext.getCurrentInstance().update("treeSegmentForm askSessionDialog askTurnOffDialog askSessionDialog1 askTurnOffDialog1");

Thanks in advance for constructive posts and comments.


Solution

  • SOLVED This is the best approach that works for me now.

    <h:form>
    ...
    <p:confirmDialog id="askSessionDialog" widgetVar="askSessionDialog" severity="alert"
                                     appendTo="@(body)" rendered="#{treeData.askSessionDialogRendered}" visible="#{treeData.askSessionDialogRendered}">
                        <f:facet name="message">
                            <h:outputText value="#{msg.WEB_ADMIN_PAGES_TREESEGMENT_NOSESSION}" escape="false"/>
                        </f:facet>
    
                        <h:form>
                            <p:commandButton value="#{msg.WEB_BUTTONS_OK}" icon="fa fa-check" type="button" accesskey="o">
                                <p:ajax event="click" listener="#{treeData.save(false, true)}" oncomplete="PF('askSessionDialog').hide()"
                                        update="@(form)" />
                            </p:commandButton>
                            <p:commandButton value="#{msg.WEB_BUTTONS_CANCEL}" icon="fa fa-close" type="reset" accesskey="c">
                                <p:ajax event="click" listener="#{treeData.setAskSessionDialogRendered(false)}"
                                        onsuccess="PF('askSessionDialog').hide()" update="@(form)" />
                            </p:commandButton>
                        </h:form>
                    </p:confirmDialog>
    ...
    </h:form>
    

    BACKEND

    setAskSessionDialogRendered(true);
    RequestContext.getCurrentInstance().update("treeSegmentForm");
    

    SPACIAL THANKS TO: @YagamiLight He helped me to kick off my solution.