user1806180
user1806180

Reputation: 11

why JSF 2.0 "rendered" does not work without refreshing the page?

When I click a method to render a part of the page, it does not change anything until I manually refresh the page.

Here is the bean:

boolean showPage = true;

public boolean getShowPage(){
    return showPage;
}

Here is the view:

<h:form>
    <p:commandButton value="Click" action="#{bean.hideContents()}" />
</h:form>

<p:panel rendered="#{bean.showPage}">
    Contents 
</p:panel>

The panel gets hidden when I manually refresh the page, otherwise it does not. How is this caused and how can I solve it?

Upvotes: 0

Views: 2907

Answers (1)

BalusC
BalusC

Reputation: 1109715

You need to update a parent component of the conditionally rendered component. You can do that by specifying its client ID in the update attribute of the <p:commandButton>:

<h:form>
    <p:commandButton value="Click" action="#{bean.hideContents}" update=":panel" />
</h:form>

<h:panelGroup id="panel">
    <p:panel rendered="#{bean.showPage}">
        Contents 
    </p:panel>
</h:panelGroup>

See also:

Upvotes: 6

Related Questions