20
Mar

Facelets Explored

   Posted by: Vivek Khokhar   in java

JSF’s Application includes:
a default ActionListener, ELResolver, StateManager, NavigationHandler, and ViewHandler.
Facelets is used as the application’s ViewHandler, represented by the class com.sun.facelets.FaceletViewHandler.

An excellent tutorial for kickstart
https://facelets.dev.java.net/nonav/docs/dev/docbook.html#gettingstarted-dependencies

Points to remember :

1. First you create a template file that will decide the layout of your page in a broader sense. or you can call it default view. Mostly using <ui:insert> tags that can be inserted or overwritten upon by child templates. For example: <ui:insert name=”leftPane”> will define a default leftpane html for your page

2. Next you define Child templates that will override the layout as per their need.
The <ui:composition> uses the template attribute to reference main template for look and feel of the page. Its like inheriting look and feel from a Default layout. This is really a powerful way of reusing UI.
If a child template doesn’t override the insertion point with the specified name (title or body), then the default text from the original template is used.

<ui:define> tags are specified with names that match the <ui:insert> tags used in the parent-template.
<ui:define name=”leftpane”> will replace <ui:insert name=”leftPane”> html definition.
This means that when Facelets builds your page, those blocks of content will be placed appropriately in the template. Any text that happens to reside inside the <ui:composition> tag, but outside of the <ui:define> tags is not displayed in the rendered output.

For example a child template for registration page:

<ui:composition template=”/Path-to/parent-layout.xhtml”>
<ui:define name=”leftpane”>
HTML for how left pane will look like in registration page
</ui:define>

This text will not appear in output because this is outside define block, you cannot write outside define blocks, it will be ignored.
</ui:composition>
This text will not appear in output because this is outside composition block, you cannot write outside define blocks, it will be ignored

3. Ok what if you want to print some attribute value of a bean.
In JSF you refer to the Beans as follows :
#{GetNameBean.helloAction} where helloAction is either getter function or someother public member function

This entry was posted on Monday, March 20th, 2006 at 8:46 am and is filed under java. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a reply

You must be logged in to post a comment.