【问题标题】:How to render a panelGroup with a h:commandLink and f:ajax如何使用 h:commandLink 和 f:ajax 呈现 panelGroup
【发布时间】:2012-12-24 19:04:48
【问题描述】:

我想在用户点击<h:commandLink> 时呈现<h:panelGroup>

我可以在没有 ajax 的情况下让它工作,但整个页面都被刷新了。当我尝试使用<f:ajax> 时,不会调用该操作。

这是怎么引起的,我该如何解决?

这是我的链接代码:

   <a4j:outputPanel>
        <h:commandLink action="#{ObjetEleve.showInfosPersos}" style="text-decoration:none;">
            <a4j:ajax event="click" render=":corps:panelInfos"/>
            <a4j:outputPanel layout="block" styleClass="menu_item_static_header">
                <h:panelGroup layout="block" styleClass="menu_item_static">
                    <h:outputText value="#{(ObjetEleve.displayModifications) ? 'Retour au mur' : 'Modifier mes informations'}" />
                </h:panelGroup>
            </a4j:outputPanel>
        </h:commandLink>
    </a4j:outputPanel>

这是我想要渲染的面板代码:

 <h:panelGroup id="panelInfos">
    <h:panelGroup id="infoPerso"
        rendered="#{(ObjetEleve.displayModifications) ? true : false}"
        layout="block">
        <a4j:outputPanel id="infosPersos" layout="block">
            <h:panelGrid width="580" columns="2" border="0">
                <h:panelGrid id="panelInscription" columns="2" border="0"
                    cellspacing="0" cellpadding="0">
                    <a4j:outputPanel>
                        <h:outputText value="Nom" />
                        <h:outputText value="*" style="color:#ff0000;" />
                    </a4j:outputPanel>
                    <a4j:outputPanel>
                        <h:inputText id="nomInscription"
                            value="#{ObjetEleve.nom_eleve}" styleClass="inputbox"
                            required="true" requiredMessage="Nom obligatoire" />
                    </a4j:outputPanel>
                    <h:outputText value="" />
                    <h:outputText value="" />
                    <a4j:outputPanel>
                        <h:outputText value="Prénom" />
                        <h:outputText value="*" style="color:#ff0000;" />
                    </a4j:outputPanel>
                    <a4j:outputPanel>
                        <h:inputText id="pnomInscription"
                            value="#{ObjetEleve.prenom_eleve}" styleClass="inputbox"
                            required="true" requiredMessage="Prénom obligatoire" />
                    </a4j:outputPanel>
                    <h:outputText value="" />
                    <h:outputText value="" />
                    <a4j:outputPanel id="pwd">
                        <h:outputText value="Mot de passe" />
                        <h:outputText value="*" style="color:#ff0000" />
                    </a4j:outputPanel>
                    <a4j:outputPanel>
                        <h:inputSecret id="passwd" value="#{ObjetEleve.pwd_eleve}"
                            redisplay="true" styleClass="inputbox" required="true"
                            requiredMessage="Mot de passe obligatoire" />
                    </a4j:outputPanel>
                    <h:outputText value="" />
                    <h:outputText value="" />
                    <a4j:outputPanel id="classe">
                        <h:outputText value="Classe" />
                        <h:outputText value="*" style="color:#ff0000" />
                    </a4j:outputPanel>
                    <a4j:outputPanel>
                        <rich:select value="#{ObjetEleve.id_classe_eleve}">
                            <f:selectItems value="#{classeBean.classes}" var="classe"
                                itemValue="#{classe.id_classe}"
                                itemLabel="#{classe.nom_classe}" />
                        </rich:select>
                    </a4j:outputPanel>
                    <h:outputText value="" />
                    <h:outputText value="" />
                    <a4j:outputPanel>
                        <h:outputText value="E-Mail" />
                        <h:outputText value="*" style="color:#ff0000" />
                    </a4j:outputPanel>
                    <a4j:outputPanel>
                        <h:inputText id="email" size="30"
                            value="#{ObjetEleve.email_eleve}" styleClass="inputbox"
                            required="true" requiredMessage="Email obligatoire" />
                    </a4j:outputPanel>
                    <h:outputText value="" />
                    <h:outputText value="" />
                    <a4j:outputPanel>
                        <h:outputText value="Date de naissance" />
                        <h:outputText value="*" style="color:#ff0000" />
                    </a4j:outputPanel>
                    <a4j:outputPanel>
                        <rich:calendar value="#{ObjetEleve.date_naissance_eleve}"
                            required="true"
                            requiredMessage="Date de naissance obligatoire" />
                    </a4j:outputPanel>
                    <h:outputText value="" />
                    <h:outputText value="" />
                    <a4j:outputPanel>
                        <h:outputText value="" />
                    </a4j:outputPanel>
                    <a4j:outputPanel>
                        <h:commandButton value="Mettre à jour les informations"
                            styleClass="submitButton" />
                    </a4j:outputPanel>
                    <h:outputText value="" />
                    <h:outputText value="" />
                </h:panelGrid>
            </h:panelGrid>
        </a4j:outputPanel>
    </h:panelGroup>
</h:panelGroup>

【问题讨论】:

  • 呃,您没有使用问题标题中暗示的标准 JSF &lt;f:ajax&gt;,但您实际上使用的是 RichFaces/Ajax4jsf &lt;a4j:ajax&gt;,如代码所示。如果你只使用&lt;f:ajax render=":corps:panelInfos"/&gt; 怎么办?
  • 哦,对,对不起...我曾经尝试使用&lt;f:ajax&gt;,但当我发布时,我只是尝试使用&lt;a4j:ajax&gt;。它适用于您的解决方案,我正在使用&lt;f:ajax event="click" render=":corps:panelInfos"&gt; 再次为我节省了 BalusC,非常感谢 :)
  • 我把它作为答案转发了。

标签: jsf rendering ajax4jsf


【解决方案1】:

您将通过event="click" 覆盖操作组件的默认ajax 事件,即event="action"。这样 JSF 不会将动作事件排队到动作方法中。

所以,请使用event="action"

<a4j:ajax event="action" render=":corps:panelInfos"/>

或者干脆完全删除它,它已经是默认事件了

<a4j:ajax render=":corps:panelInfos"/>

同样的故事也适用于&lt;f:ajax&gt;

另见:

【讨论】:

  • 好吧,默认情况下我不知道 event="action" 。我现在会记得的:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-07-20
  • 1970-01-01
  • 2012-04-13
  • 2015-05-08
  • 2014-02-22
  • 1970-01-01
  • 2011-07-19
相关资源
最近更新 更多