是否可以在JSF 2中使用带有复合组件的模板?

时间:2012-03-22 07:09:52

标签: templates jsf-2 composite-component

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    ...
    template="inputLayout.xhtml">

    <composite:interface>
        <composite:attribute name="name" />
        <composite:attribute name="value" />
    </composite:interface>

    <composite:implementation>
      <!-- <ui:define name="content"> -->
          <h:message for="textPanel" style="color:red;" />
          #{cc.attrs.name} : 
          <h:inputText id="name" value="#{cc.attrs.value}" />
      <!-- <ui:define> -->
    </composite:implementation>
</ui:composition>

问题在于,甚至 ui:define 都会对内容进行评论。 所以它就像 ui:define 被忽略或者我错过了一些东西? 感谢。

1 个答案:

答案 0 :(得分:7)

这确实行不通。您需要在实现中使用<ui:decorate>

<ui:component
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:cc="http://java.sun.com/jsf/composite"
>
    <cc:interface>
        ...
    </cc:interface>
    <cc:implementation>
        <ui:decorate template="/WEB-INF/inputLayout.xhtml">
            <ui:define name="content">
                ...
            </ui:define>
        </ui:decorate>
    </cc:implementation>
</ui:component>