JSF 2 ile birlikte composite component yaratmak için http://java.sun.com/jsf/composite kullanılır. /ana kök (web content bölümü)/resource/fibiler klasörü içinde yaratılan bir xhtml içinde interface elementi ile bileşenin genel yapısı , implementation elementi ile de bileşen içeriği verilmektedir. Aşağıdaki gibi bir hello.xhtml yaratalım ve resource/fibiler klasörü içine hello.xhtml olarak koyalım :
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:composite="http://java.sun.com/jsf/composite">
<composite:interface>
<composite:attribute name="value" />
</composite:interface>
<composite:implementation>
<h:outputLabel value="Merhaba #{cc.attrs.value}"></h:outputLabel>
</composite:implementation>
</html>
composite:interface ile genel yapısı , implementation ile içeriği verilmiştir.
Bu bileşeni aşağıdaki gibi bir sayfada kullanabiliriz :
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:fb="http://java.sun.com/jsf/composite/fibiler">
<fb:hello value="Fibiler"></fb:hello>
</html>
Bu sayfası çağrıldığında ekranda Merhaba Fibiler yazısı gözükür.