JSF <ui:include> contains page with preRenderView event not trigger in <h:body>

247 Views Asked by At

I am using JSF 2.0.1 and observe a difference when try to add header.xhtml onto other page with <ui:include src="header.xhtml"></ui:include>, the code example below:

header.xhtml

This page will be add as one component onto major page, it contains preRenderView event used for checking whether user is permitted to log on that major page.

<h:head>
    <title>Header</title>
</h:head>
    <f:event type="preRenderView" listener="#{authorize.checkAuthentication}"/>
<h:body></h:body>

If I am using <ui:include src="header.xhtml"></ui:include> inside <h:body> section on major page as below:

Major.xhtml

<h:head>
    <title>Major</title>
</h:head>
<h:body>
    <ui:include src="header.xhtml"></ui:include>
    <f:view></f:view>
</h:body>   

The problem is <f:event> in header.xhtml not triggered, in another word checkAuthentication function not work in this case.

But if I move <ui:include src="header.xhtml"></ui:include> out of <h:body> section on major page and put it ahead of <h:body>, the event triggered and function works.

<h:head>
    <title>Major</title>
</h:head>
<ui:include src="header.xhtml"></ui:include>
<h:body>       
    <f:view></f:view>
</h:body>   

Could someone help me to explain why this difference happens ? Is there any professional way to solve this case, as keep the header page content and also trigger the event ? Thanks

Note: Also I check on this ticket, but not sure we are the same case

0

There are 0 best solutions below