How do I include a body into a tagfile

一曲冷凌霜 提交于 2019-12-08 04:16:33

问题


I have a tagfile I intend to use as an input template:

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

It is stored in my /WEB-INF/tags folder with a .taglib.xml and necessary web.xml context-param.

I understand it could be used as follows:

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

at the moment this is in its most basic form. I intend to use various and complex inputs. but the layout of the label etc will always need to stay the same.

How do I include the body of the <g:question> in the tagfile?


回答1:


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

Do note that you can even use <ui:define name="..."> and <ui:insert name="..."> on tagfiles like as you usually do on templates.



来源:https://stackoverflow.com/questions/28214221/how-do-i-include-a-body-into-a-tagfile

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