1

考虑一个嵌套模板:

基础.xhtml:

...

<h:outputText value="#{uiParamter}"/>
<ui:insert name="header"/>

... etc.

布局.xhtml:

<ui:composition template="Base.xhtml">

    ...

    <ui:insert name="content"/>

    ... etc.

</ui:composition>

现在像这样定义模板客户端时:

<ui:composition template="Layout.xhtml">

    <ui:define name="header"> foo </ui:define>
    <ui:define name="content"> foo2 </ui:define>
    <ui:param name="uiParameter" value="foo3"/>

</ui:composition>

是否必须通过重新定义将模板中的<ui:param>或转发到模板。例如:<ui:define>Layout.xhtmlBase.xhtml

<ui:param name="uiParameter" value="#{uiParameter}">  
<ui:define name="header">
    <ui:insert name="header"/>
</ui:define>

也可以将这个问题改写为:“模板参数是否具有级联行为?”

4

1 回答 1

4

答案是肯定的。我在 JBoss AS 7.0 上运行了以下代码:

巢1.xhtml:

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets">
    
    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title><ui:insert name="title">
                Nested
            </ui:insert></title>
    </h:head>
    
    <h:body>
        <ui:insert name="main" />
        <h:outputText value="#{uiParam}"/>
    </h:body>

</html>

巢2.xhtml:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets" template="nest1.xhtml">

    <ui:define name="main">
        <p>Nested templated content.</p>
    </ui:define>
</ui:composition>

巢3.xhtml:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets" template="nest2.xhtml">

    <ui:define name="title">Nested Template</ui:define>
    <ui:param name="uiParam" value="ui param value" />
</ui:composition>

呈现为:

jboss输出截图

于 2012-09-12T15:25:58.197 回答