JSF 2.0 Facelets template inheritance

假如想象 提交于 2019-12-21 20:14:07

问题


This is an extended repost of JSF 2.0 Facelets nested templates inheritance, which was loosely asked and formally answered.

Here is my easy_to_earn question:

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>

Next, I want another template, form_wrapped.xhtml, which would extend base_template.xhml but with main_content wrapped by <h:form>:

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

And the page itself:

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

How do I do this?


回答1:


Make your form_wrapped template like this:

<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>


来源:https://stackoverflow.com/questions/5646624/jsf-2-0-facelets-template-inheritance

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!