只是一个问题....不知道我是否做对了,或者这是否不适用于规范。我制作了一个简单的 facelets 主模板,如下所示:
模板.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
<ui:insert name="metadata" />
<h:head>
.... here the rest of template with other <ui:insert>
客户端很简单,使用模板:
main.xhtml
<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
template="./WEB-INF/template/template.xhtml">
<ui:define name="metadata">
<ui:include src="./WEB-INF/template/securityCheck.xhtml" />
</ui:define>
... here goes the rest with other <ui:define> and <ui:include> ....
在securityCheck.xhtml中,简单f:viewAction
如下:
安全检查.xhtml
<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:metadata>
<f:viewAction action="#{loginController.doLoginCheck()}" />
</f:metadata>
</ui:composition>
好吧,在这种情况下, f:viewAction 没有被调用,相反,如果我直接将代码扩展到元数据部分,如下所示:
main.xhtml
<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
template="./WEB-INF/template/template.xhtml">
<ui:define name="metadata">
<f:metadata>
<f:viewAction action="#{loginController.doLoginCheck()}" />
</f:metadata>
</ui:define>
... here goes the rest with other <ui:define> and <ui:include> ....
它就像一个魅力(如预期的那样)。为什么将元数据部分包含在模板客户端中不起作用?如果有正确的方法来做到这一点,我如何在包含的调用之后添加其他 f:viewAction 调用?像这样的东西:
其他页面.xhtml
<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
template="./WEB-INF/template/template.xhtml">
<ui:define name="metadata">
<ui:include src="./WEB-INF/template/securityCheck.xhtml" />
<f:metadata>
<f:viewAction action="#{myBean.doSomething()}" />
</f:metadata>
</ui:define>
... here goes the rest with other <ui:define> and <ui:include> ....
如果这是正确的,呼叫是否按此特定顺序进行?
我将 JavaEE 7/JSF 2.2 与 Glassfish 4.1 和 Mojarra 2.2.12 impl 一起使用。
谢谢你。