maximus
maximus

Reputation: 11524

p:outputPanel does not render page sections

I have two p:ouputPanels which have the rendered attribute. They should be rendered when the value of the underlying getter/setter changes. However, the underlying values change in the right order. The first panel disappears, However the second panel does not show up. Even NOT in the HTML code!

My two panels:

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

I appreciate your answer!!!

-UPDATE-

In the code, I reference to the persist method and in this method I change the getter and setter of the visibility for each section.

-UPDATE1-

OK here is in fact my code:

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

I really do not see where it fails? ;(

Upvotes: 2

Views: 5848

Answers (2)

Andy
Andy

Reputation: 6568

It's like Xtreme Biker said <f:ajax> render attribute will render elements that are already present in the DOM. In your case, <p:outputPanel id="PanelThank"> render attribute was evaluating to false so it was not in the DOM. Therefore, <f:ajax> could not render it. You need to point to something that is always visible. Change

<f:ajax render="" />

to

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

but more importantly change

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

to

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

Consider refactoring your code also. For instance, action and method in <h:form> is not needed.

Upvotes: 3

Aritz
Aritz

Reputation: 31651

rendered attribute defines if JSF will render your component in the DOM tree. Your problem is you cannot update a component which is not in the tree because you simply don't have it:

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

Your best is to wrap your content in another container which is always rendered and update it instead of the other one:

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

<p:ajax update="updatablePanel"/>

Upvotes: 1

Related Questions