【问题标题】:JSF 2.0 Facelets template inheritanceJSF 2.0 Facelets 模板继承
【发布时间】:2011-08-04 12:49:50
【问题描述】:

这是JSF 2.0 Facelets nested templates inheritance的扩展转贴,被粗略地询问并正式回答。

这是我的 easy_to_earn 问题:

template_base.xhml

<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><!-- header stuff --></h:head>
<h:body>
    <!-- Lot of html here -->
    <div id="main">
        <ui:insert name="main_content"/>
    </div>
    <!-- Lot of html here -->
</h:body>
</html>

接下来,我想要另一个模板,form_wrapped.xhtml,它将扩展 base_template.xhml,但main_content 被@987654324 包裹@:

<div id="main">
    <h:form>
        <!-- "main_content" goes here -->
    </h:form>
</div>

还有页面本身:

<ui:composition template="/WEB-INF/templates/form_wrapped.xhtml">
    <ui:define name="main_content">
            <!-- this html is wrapped by form -->
    </ui:define>
</ui:composition>

我该怎么做?

【问题讨论】:

    标签: java jsf jsf-2


    【解决方案1】:

    像这样制作你的form_wrapped 模板:

    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        template="/WEB-INF/templates/main_wrapped.xhtml">
    
        <ui:define name="main_content">
                <div id="main">
                    <h:form>
                        <ui:insert name="form_content" />
                    </h:form>
                </div>
        </ui:define>
    
    </ui:composition>
    

    【讨论】:

    • 谢谢,我是否可以使用相同的“main_content”引用而不是引入新的“form_content”?
    • @Osw 是的,我相信您可以通过在 form_wrapped.xhtml 模板中将 &lt;ui:insert name="form_content" /&gt; 替换为 &lt;ui:insert name="main_content" /&gt; 来做到这一点
    猜你喜欢
    • 1970-01-01
    • 2010-11-22
    • 2010-12-28
    • 2012-03-06
    • 2011-03-28
    • 1970-01-01
    • 2012-04-19
    • 1970-01-01
    相关资源
    最近更新 更多