Hen
Hen

Reputation: 253

p: dialog is not working as expected?

i have two p:commandLink:

 <p:commandLink update=":form:livreDetail" oncomplete="PF('livreDialog').show()" title="View Detail">
    <h:outputText styleClass="ui-icon ui-icon-search" style="margin:0 auto;" />
    <f:setPropertyActionListener value="#{livre}" target="#{livreDataGridView.selectedLivre}" />
</p:commandLink>
<p:commandLink update=":form:ajoutPanel" oncomplete="if(#{ empty loginBean.c }){PF('connectDialog').show()}else {PF('ajoutLivrePanier').show()} " title="ajouter au panier">
    <h:outputText styleClass="ui-icon ui-icon-cart" style="margin:0 auto;" />
    <f:setPropertyActionListener value="#{livre}" target="#{livreDataGridView.selectedLivre}" />
</p:commandLink>

The first p:commandLink one is showing and updating the content of livreDialog p:dialog.

The second p:commandLink should show connectDialog p:dialog when loginBean.c property is null, and ajoutLivrePanier p:dialog when is not.

my code works correctly when the loginBean property is null. But when is not it gives strange results:

  1. When i click the first p:commandLink it only shows the livreDialog p:dialog without updating it's content. Also the validation message of the connectDialog p:dialog is shown up. it is weird !!
  2. When i click the second p:commandLink only the validation message of connectDialog p:dialog is shown up, Weird too !!

Here is the hole code:

<p:messages globalOnly="true" autoUpdate="true" showDetail="false"/>
<h:form id="form">
    <p:dataGrid var="livre" value="#{livreListBean.livresList}" columns="3"
                rows="12" paginator="true" id="livres"
                    paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                    rowsPerPageTemplate="6,12,16">
        <f:facet name="header">
            Livres
        </f:facet>
        <p:panel header="#{livre.titre}" style="text-align:center">
            <h:panelGrid columns="1" style="width:100%">
                <h:outputText value="#{livre.auteur}" />
                <h:outputText value="#{livre.datePublication}" />
                <p:commandLink update=":form:livreDetail" oncomplete="PF('livreDialog').show()" title="View Detail">
                    <h:outputText styleClass="ui-icon ui-icon-search" style="margin:0 auto;" />
                    <f:setPropertyActionListener value="#{livre}" target="#{livreDataGridView.selectedLivre}" />
                </p:commandLink>
                <p:commandLink update=":form:ajoutPanel" oncomplete="if(#{ empty loginBean.c }){PF('connectDialog').show()}else {PF('ajoutLivrePanier').show()} " title="ajouter au panier">
                    <h:outputText styleClass="ui-icon ui-icon-cart" style="margin:0 auto;" />
                    <f:setPropertyActionListener value="#{livre}" target="#{livreDataGridView.selectedLivre}" />
                </p:commandLink>
            </h:panelGrid>
        </p:panel>
    </p:dataGrid>

    <p:dialog header="Info Livre" widgetVar="livreDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
        <p:outputPanel id="livreDetail" style="text-align:center;">
            <p:panelGrid  columns="2" rendered="#{not empty livreDataGridView.selectedLivre}" columnClasses="label,value">

                <h:outputText value="Titre:" />
                <h:outputText value="#{livreDataGridView.selectedLivre.titre}" />

                <h:outputText value="Auteur" />
                <h:outputText value="#{livreDataGridView.selectedLivre.auteur}" />

                <h:outputText value="Date de publication:" />
                <h:outputText value="#{livreDataGridView.selectedLivre.datePublication}" />

                <h:outputText value="Prix" />
                <h:outputText value="$#{livreDataGridView.selectedLivre.prix}" />
            </p:panelGrid>
        </p:outputPanel>
    </p:dialog>

    <h:panelGroup id="livrePanier">
        <p:dialog header="Se connecter" widgetVar="connectDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
            <p:outputPanel id="connecterPanel" style="text-align:center;">
                <h:panelGrid  columns="3" >

                    <p:outputLabel for="mail" value="E-mail:" />
                    <p:inputText id="mail" value="#{loginBean.email}" required="true" requiredMessage="Vous devez entrer votre e-mail"/>
                    <p:message for="mail"/>

                    <p:outputLabel for="password" value="Password:" />
                    <p:password id="password" value="#{loginBean.password}" required="true" requiredMessage="Vous devez entrer votre password"/>
                    <p:message for="password"/>
                    <p:commandButton value="Se connecter" action="#{loginBean.LoginProcess()}" process="connecterPanel" update="connecterPanel"/>
                </h:panelGrid>
            </p:outputPanel>
        </p:dialog>
        <p:dialog header="Ajouter au panier" widgetVar="ajoutLivrePanier" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
            <p:outputPanel id="ajoutPanel" style="text-align:center;" rendered="#{not empty livreDataGridView.selectedLivre}">
                <p:outputLabel value="Voulez vous ajouter ce produit au panier ?"/> 
                <h:panelGrid  columns="2" >
                    <p:outputLabel value="#{livreDataGridView.selectedLivre.titre}" />
                    <p:outputLabel value="#{livreDataGridView.selectedLivre.prix}" />
                    <p:commandButton value="Oui" action="#{livreDataGridView.ajouterLivreAuPanier()}" process="connecterPanel" update="connecterPanel" oncomplete="PF('ajoutLivrePanier').hide()"/>                                   
                    <p:commandButton value="Annuler" onclick="PF('ajoutLivrePanier').hide()"/>
                </h:panelGrid>
            </p:outputPanel>
        </p:dialog>
    </h:panelGroup>
</h:form>

i'll appreciate your help to fix the problem

Upvotes: 2

Views: 973

Answers (1)

Vsevolod Golovanov
Vsevolod Golovanov

Reputation: 4206

You need process="@this" on your commandLinks. Without it JSF processes the whole form, that's why you see those validation failures, which in turn cause the Invoke Application phase to be skipped.

See also: Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes.

Upvotes: 3

Related Questions