0

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user1806180
  • 11
  • 2
  • 4

1 Answers1

6

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555