p:outputPanel不呈现页面部分

时间:2013-07-19 11:09:46

标签: jsf jsf-2 primefaces

我有两个p:ouputPanels具有rendered属性。当底层getter/setter的值发生变化时,应该呈现它们。但是,基础值以正确的顺序改变。第一个面板消失,但第二个面板没有显示。即使不在HTML代码中!

我的两个小组:

    <p:outputPanel id="PanelParent">

     <h:form>
        <p:outputPanel id="PanelForm" rendered="#{PageService.isVisibilityForm()}">

        <h:commandButton value="Button"
                                            action="#{PageService.persist}"
                                            styleClass="btn btn-primary opal_btn submit_form_new" />
     </h:form>                      
        </p:outputPanel>

        <p:outputPanel id="PanelMessage" rendered="#{PageService.isVisibilityMessage()}">

        //Message

        </p:outputPanel>

    </p:outputPanel>

感谢您的回答!

-UPDATE -

在代码中,我引用了persist方法,在这个方法中,我更改了每个部分的可见性的getter和setter。

-UPDATE1 -

好的,这就是我的代码:

            <p:outputPanel id="parentPanel">
                <p:outputPanel id="PanelForm"
                    rendered="#{PageService.isVisibilityForm()}">
                    <div>
                        <div>
                            <h:form class="homepage_invitee_form" action="" method="POST">

                                <p:messages id="messages" showDetail="false" autoUpdate="true"
                                    closable="true" />

                                <h:inputText required="true"
                                    value="#{PageService.instance.name}"
                                    name="name" placeholder="Last Name"
                                    styleClass="lastname_new" id="lastname_new"
                                    type="text placeholder" />

                                <h:commandButton value="Press"
                                    action="#{PageService.persist()}"/>

                                    <f:ajax render="" />
                                </h:commandButton>

                            </h:form>
                        </div>

                    </div>
                </p:outputPanel>

                <p:outputPanel id="PanelThank"
                    rendered="#{PageService.isVisibilityThank()}">
                    <div>
                        Message
                    </div>
                </p:outputPanel>
            </p:outputPanel>

我真的不知道失败的地方? ;(

2 个答案:

答案 0 :(得分:3)

就像Xtreme Biker所说<f:ajax> render属性将呈现DOM中已存在的元素。在您的情况下,<p:outputPanel id="PanelThank"> render属性正在评估false,因此它不在DOM中。因此,<f:ajax>无法呈现它。你需要指出一些始终可见的东西。改变

<f:ajax render="" />

<f:ajax render=":PanelThank" />

但更重要的是改变

<p:outputPanel id="PanelThank" rendered="#{PageService.isVisibilityThank()}">
    <div>
        Message
    </div>
</p:outputPanel>

<p:outputPanel id="PanelThank">
    <p:outputPanel rendered="#{PageService.isVisibilityThank()}">
        <div>
            Message
        </div>
    </p:outputPanel>           
</p:outputPanel>

考虑重构代码。例如,action中不需要method<h:form>

答案 1 :(得分:1)

rendered属性defines if JSF will render your component in the DOM tree。您的问题是您无法更新不在树中的组件,因为您根本没有它:

<p:outputPanel id="PanelForm" rendered="#{PageService.isVisibilityForm()}">
    //my Form
<p:outputPanel>

<!--Fails if not PageService.isVisibilityForm(), because you don't have the component itself in the tree! So can't find it-->
<p:ajax update="PanelForm"/>

您最好将内容包装在另一个容器中,该容器始终呈现并更新而不是另一个容器:

<h:panelGroup id="updatablePanel">
    <p:outputPanel rendered="#{PageService.isVisibilityForm()}">
        //my Form
    <p:outputPanel>
</h:panelGroup>

<p:ajax update="updatablePanel"/>
相关问题