1

我正在使用 JSF 2.0.1 并在尝试添加header.xhtml到其他页面时观察到差异<ui:include src="header.xhtml"></ui:include>,代码示例如下:

header.xhtml

该页面将作为一个组件添加到主页面上,它包含preRenderView用于检查是否允许用户登录该主页面的事件。

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

如果我在主要页面上使用<ui:include src="header.xhtml"></ui:include> 内部部分,如下所示: <h:body>

主要.xhtml

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

问题在于<f:event>header.xhtml触发,换句话说,在这种情况下checkAuthentication功能不起作用。

但是,如果我移出主要页面<ui:include src="header.xhtml"></ui:include>的部分并将其放在前面,则事件触发并且功能起作用。<h:body> <h:body>

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

有人可以帮我解释为什么会发生这种差异吗?有什么专业的方法可以解决这种情况,既保留页眉内容,又触发事件?谢谢

注意:我也检查了这张票,但不确定我们是否相同

4

0 回答 0