【问题标题】:How do I include a body into a tagfile如何将正文包含到标记文件中
【发布时间】:2015-03-28 15:35:35
【问题描述】:

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

<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.xml 和必要的web.xml 上下文参数。

我知道它可以如下使用:

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

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

如何在标签文件中包含&lt;g:question&gt; 的正文?

【问题讨论】:

    标签: jsf facelets jsf-2.2 tagfile


    【解决方案1】:

    使用&lt;ui:insert&gt;

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

    请注意,您甚至可以在标记文件上使用 &lt;ui:define name="..."&gt;&lt;ui:insert name="..."&gt;,就像在模板上一样。

    【讨论】:

    • 再次感谢鲍克。如果没有您的 SO 贡献,JSF 将变得更加困难。
    猜你喜欢
    • 2012-04-19
    • 1970-01-01
    • 2023-03-03
    • 2017-09-30
    • 1970-01-01
    • 2021-12-22
    • 2013-01-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多