Your First Cup: An Introduction to the Java EE Platform

ProcedureCreating the inputDate Composite Component

Create the inputDate composite component as a resource in the components resource library.

  1. In the firstcup project select the resources/components directory and then select File->New File.

  2. Select JavaServer Faces under Categories, Facelets Simple File under File Types, and click Next.

  3. Enter inputDate under File Name and click Finish.

  4. In the newly created inputDate.xhtml replace the <html> tag with the following:

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
          xmlns:composite="http://java.sun.com/jsf/composite"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core">

    The inputDate.xhtml composite component uses the Facelets Composite Component, the HTML Render Kit, and the JSF Core tag libraries.

  5. Add the composite component interface definition between the <body> and </body> tags in inputDate.xhtml:

    <body>
    	<composite:interface>
    		<composite:attribute name="date" required="true" />
    	</composite:interface>
    </body>
  6. Add the composite component implementation below the interface definition:

    ...
    	</composite:interface>
    	<composite:implementation>
    		<h:inputText value="#{cc.attrs.date}">
    			<f:convertDateTime pattern="MM/dd/yyyy" />
    		</h:inputText>
    	</composite:implementation>
    </body>
  7. Right-click in the editor window and select Format.

  8. Select File->Save.