Search code examples
jsf-2

@postconstruct method gets called during ajax-refresh the main content part by navigation menu


I am trying to ajax-refresh the main-content from navigation menu.

The requirement is exactly the same in the link

How to ajax-refresh dynamic include content by navigation menu? (JSF SPA)

following the pattern answered by BalusC,

<h:panelGroup id="content" layout="block">
<h:form id="contentform">
    <h:panelGroup rendered="#{bean.page == 'include1'}">
        <ui:include src="include1.xhtml" />
    </h:panelGroup>
    <h:panelGroup rendered="#{bean.page == 'include2'}">
        <ui:include src="include2.xhtml" />
    </h:panelGroup>
    <h:panelGroup rendered="#{bean.page == 'include3'}">
        <ui:include src="include3.xhtml" />
    </h:panelGroup>
</h:form>

Each xhtml has its own managed bean with @PostConstruct method, the problem is all the @PostConstruct method gets called irrespective of rendered condition.


Solution

  • <ui:include/> is a taghandler while <h:panelGroup/> is a render-time tag. The difference is that they're both active at different times during the lifecycle of the build. In this particular case, <ui:include/> is active and processed before the <h:panelGroup/>. So while your render condition might hide the dynamic include at render time, the include would still go thru the grinder anyway, resulting in the processed managed beans.

    You should place the rendered attribute on the <ui:include/> instead. Be sure that the render condition is not also dependent on some other render time construct