Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
921 views
in Technique[技术] by (71.8m points)

jsf 2 - Is it possible to use template with composite component in JSF 2?

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

The problem is that even the ui:define is commented the content is rendered. So it is like the ui:define is ignored or Am I missing some thing ? Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This will indeed not work. You need <ui:decorate> inside the implementation instead.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...