why JSF 2.0 “rendered” does not work without refre

2019-06-09 00:52发布

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?

标签: jsf render
1条回答
Anthone
2楼-- · 2019-06-09 01:23

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:

查看更多
登录 后发表回答