Skip to main content

JSF2 Composite Component Metadata

Posted by edburns on September 2, 2009 at 9:53 AM PDT

This ultra-quick blog entry shows how to use the JSF runtime to
access metadata for a composite component. Note that most of the
metadata is optional when creating a composite component, therefore,
this entry will be of interest to tool vendors and those wishing to
write composite components that stand a chance of showing up nicely in

The Using Page

When showing a composite component demo, I always like to start out
with the using page.

Listing 1: the using page

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
  2. <html xmlns=""
  3.      xmlns:h=""
  4.      xmlns:f=""
  5.      xmlns:my=""
  6.      xmlns:meta="">
  7. <h:head>
  8.   <title>A Simple JavaServer Faces 2.0 View</title>
  9. <style type="text/css">
  10. .grayBox { padding: 8px; margin: 10px 0; border: 1px solid #CCC; background-color: #f9f9f9;  }
  12. </h:head>
  13. <h:body>
  14.   <h:form>
  16.     <p>Composite Component usage:</p>
  18. <div id="cc" class="grayBox" style="border: 1px solid #090;">
  19. <my:myComponent loginAction="#{userBean.loginAction}" />
  20. </div>
  22. <h2>Metada for This Composite Component</h2>
  24. <div id="foo" class="grayBox" style="border: 1px solid #090;">
  25.     <pre>
  26.     <meta:printMetadata viewName="main.xhtml" libraryName="cc"
  27.                        resourceName="myComponent.xhtml"/>
  28.     </pre>
  29. </div>
  32.     <p><h:commandButton value="submit" /></p>
  33.   </h:form>
  34. </h:body>
  35. </html>

Line 5 declares the namespace

Related Topics >>


&nbsp;Hi, In first thanks for this article and sorry for my ...


In first thanks for this article and sorry for my english.

I have a question about composite, I would like to create composite 'autonome'. So I have some difficulities to initialize it.

For example, i take a composite to edit a user like :

<mycomposite userId="theidOfTheUserToShow">

and for implementation


<composite:attribute name="userId" required="true" />



Edit : #{ctrlEditUser.username} ....


My problem is what is the best way to initialize backean? There is a way to do #{ctrlEditUser.init(userId)}, or anything way?


In JSF 2.2, we'll have UIViewAction and the ...

In JSF 2.2, we'll have UIViewAction and the <f:viewAction> tag. 

In JSF 2.1 and 2.0 you can use f:event, as shown in this demo:

Which is included from


Is there a doc tool for this yet?

The Tag Library Document Generator doesn't work against either taglib.xml or Composite component metadata that I have been able to see.

about layout

One common composite component I used with jsf 1.2 + facelets is : Which I use it like :