1

我有一个我打算用作输入模板的标记文件:

<ui:composition
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets">

    <div class="qr">
        <label>#{question}</label>
        <div class="helpButton"></div>
        <!-- body here -->
        <!-- errors output eventually to go here -->
    </div>

</ui:composition>

它与必要的上下文参数一起存储在我的/WEB-INF/tags文件夹中。.taglib.xmlweb.xml

我知道它可以按如下方式使用:

<g:question question="What is your name?" id="firstname">
    <h:inputText value="#{bean.firstname}" />
</g:question>

目前这是最基本的形式。我打算使用各种复杂的输入。但是标签等的布局总是需要保持不变。

如何<g:question>在标记文件中包含正文?

4

1 回答 1

2

使用<ui:insert>.

<ui:composition
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets">

    <div class="qr">
        <label>#{question}</label>
        <div class="helpButton"></div>
        <ui:insert />
        <!-- errors output eventually to go here -->
    </div>

</ui:composition>

请注意,您甚至可以像在模板上一样使用<ui:define name="...">和处理标记文件。<ui:insert name="...">

于 2015-01-29T13:48:29.843 回答