p: 对话没有按预期工作?

p: dialog is not working as expected?

我有两个 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>

第一个 p:commandLink 正在显示和更新 livreDialog p:dialog.

的内容

loginBean.c [=56= 时,第二个 p:commandLink 应该显示 connectDialog p:dialog ] 为 null,而 ajoutLivrePanier p:dialog 时则不是。

当 loginBean 属性 为 null 时,我的代码可以正常工作。但是什么时候不给出奇怪的结果:

  1. 当我点击第一个 p:commandLink 时,它只显示 livreDialog p:dialog 而没有更新它的内容。 connectDialog p:dialog 的验证消息也会显示出来。很奇怪!!
  2. 当我点击第二个p:commandLink时,只显示connectDialogp:dialog的验证消息,也很奇怪!!

这里是孔代码:

<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>

感谢你帮助解决问题

您的 commandLinks 需要 process="@this"。如果没有它,JSF 将处理整个表单,这就是为什么您会看到那些验证失败,这反过来会导致调用应用程序阶段被跳过。

另请参阅:Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes