Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 669
kycdev Avatar asked Mar 22 '12 07:03

kycdev


People also ask

What are composite components in jsf2?

Tags:component| jsf2 Since JSF 2.0, it’s very easy to create a reusable component, known as composite components. In this tutorial, we show you how to create a simple composite components (stored as “register.xhtml“), which is an user registration form, includes name and email text fields (h:inputText) and a submit button (h:commandButton).

How to define a custom component in JSF?

JSF provides the developers with a powerful capability to define their own custom components, which can be used to render custom contents. Defining a custom component in JSF is a two-step process. Create a resources folder. Create a xhtml file in resources folder with a composite namespace.

What is @jsf2?

JSF2.0 refers to those components that you’ve implemented with the composite library as composite components. Composing a new component is very easy, cause no need for writing a java code or adding an XML.

How do you create a composite component in HTML?

Create a xhtml file in resources folder with a composite namespace. Use composite tags composite:interface, composite:attribute and composite:implementation, to define content of the composite component. Use cc.attrs in composite:implementation to get variable defined using composite:attribute in composite:interface.


1 Answers

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>
like image 135
BalusC Avatar answered Oct 22 '22 00:10

BalusC