Friday, February 12, 2010

Writing Facelets Composite Component in JSF 2.0

JSF 2.0 is making it easier for Java EE web developers to write composite components.

Composite components are reusable custom HTML fragments + presentation logic.

I said "easier" because in JSF 1.x it was horrible. Now it's manageable, but not necessarily easier than other frameworks, like Tapestry or Wicket. At least it can compete on a similar level.

To create a composite component, write a view using Facelets XHTML like this example:
<?xml version='1.0' encoding='UTF-8' ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns=""



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



        <div style="background: red; color: yellow">



        <div style="border: 1px solid green">

            <composite:insertChildren />



Save the XHTML code above as resources/ezcomp/titleBorder.xhtml.

Composite components live under resources folder, and the namespace will be determined from the subfolder name.

Use the ezcomp:titleBorder component like this:
<?xml version='1.0' encoding='UTF-8' ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns=""




        <title>Composite Component Demo</title>



        <ezcomp:titleBorder title="Cool stuff">

            So happy to be here!



Not bad, is it? ;-)

Related posts:

1 comment:

polo outlet said... Burberry Outlet Air Max Shoes Coach Black Friday Coach Black Friday Coach Cyber Monday Coach Factory Coach Outlet Factory Coach Outlet USA Coach Purses Factory Coach Purses USA Coach Store Outlet Coach Purses On Sale Monster Beats Outlet Louis Vuitton Outlet Louis Vuitton Factory Marc Jacobs On Sale MCM Outlet MCM 店铺 cheap oakley sunglasses Michael Kors Outlet Michael Kors Outlet Michael Kors Factory Michael Kors Outlet Michael Kors Factory Online Coach Factory Outlet North Face Outlet Online Polo Outlet Store Ralph Lauren UK Sac Longchamp Pairs Coach Outlet Online Coach Factory Oultet Barbour Jackets Outlet Online Canada Goose Outlet Gucci Outlet Online Michael Kors Outlet Moncler Clearance Moncler Jackets Outlet Online North Clearace Outlet Polo Ralph Lauren Outlet Online Woolrich Clearance Michael Kors Factory Outlet Coach Outlet Online USA Beats by Dre Coach Purses Outlet Online Michael Kors USA

Post a Comment

Copyright 2009 Spring vs Java EE Web Dev. Powered by Blogger Blogger Templates create by Deluxe Templates. WP by Masterplan