Icefaces Facelets to get a template effect

I am planning to make it dynamic, but haven’t yet done the hands on.

Preparation:

include icefaces-facelets.jar

and put the following into web.xml

<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.jspx</param-value>
</context-param>

This tells JSF to assume a prefix of jspx, which the Facelet’s rendered can interpret. Facelets can use many other parameters depending on your application.

put the following into faces-config.xml

<application>
<view-handler>com.icesoft.faces.facelets.D2DFaceletViewHandler

</view-handler>

</application>

tell JSF about the Facelets view handler. This is a plug-in that handles the Render Response and Restore View phases of the JSF request-processing life cycle.

Template Idea

And then comes the confusing part, I can’t understand this after reading the document twice. I have to jump into the source and do some hands on to figure this out. I think I have a better way to present it. This may be my wrong intepretation.

You need three things.

1. a jsp that load the template

2. a jspx which is the template

3. some jspx which are components you put inside the template.

1. load template

  • <ui:composition> – This is a templating tag that wraps content to be included in another facelet. Any content outside the composition tag will be ignored by the Facelets view handler.
  • <ui:define> – This tag is a templating tag that defines named content to be inserted into a template.

example:

            <ui:composition template="mainTemplate.jspx">
<ui:define name="faceletHeader">
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8"></meta>
<title>
<ice:outputText value="Facelet Dynamic Include Tutorial"/>
</title>
<link href="./xmlhttp/css/xp/xp.css" rel="stylesheet" type="text/css"/>
</ui:define>
</ui:composition>

2. The template

  • <ui:insert>– A templating tag that declares a named content element to be defined by another Facelet. Used effectively with the ui:define tag.
  • <ui:include>– A server-side include tag for Facelets. It simply includes the document pointed to by the “src” attribute as part of the current JSF page.

example:

<ui:insert name="content">
<ui:include src="./content-facelet.jspx" />
</ui:insert>

3. Contents

just icefaces jspx that you normally write.

Conclusion:

The confusing part is when you load the template, you will have two way to actually put content inside <ui:insert>.

1. use <ui:define> inside “template load” to put content directly into it.

2. use <ui:include> inside “template” to reference a jspx.

And if I am not getting it wrong, any content inside <ui:insert> which is not <ui:include> will be replace by <ui:define> stuff.

I will update this post when I get the dynamic reference content work.

Have fun~

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s