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~
Icefaces Application on Tomcat 6 using Netbeans
Similar to the portlet development but simpler.
download latest icefaces 1.7 RC1
pack these in library manager as Icefaces 1.7 library
backport-util-concurrent.jar
commons-beanutils.jar
commons-digester.jar
commons-discovery.jar
commons-fileupload.jar
commons-logging.jar
icefaces.jar
icefaces-comps.jar
Create a web application project and use JavaServerFace framework.
include Icefaces 1.7 library that we create.
Add these to your web.xml
<servlet>
<servlet-name>Persistent Faces Servlet</servlet-name>
<servlet-class>
com.icesoft.faces.webapp.xmlhttp.PersistentFacesServlet
</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>
<servlet>
<servlet-name>Blocking Servlet</servlet-name>
<servlet-class>com.icesoft.faces.webapp.xmlhttp.BlockingServlet</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Persistent Faces Servlet</servlet-name>
<url-pattern>*.iface</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Persistent Faces Servlet</servlet-name>
<url-pattern>/xmlhttp/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Blocking Servlet</servlet-name>
<url-pattern>/block/*</url-pattern>
</servlet-mapping>
Add a jspx to you project, if you put that under Web pages/jspx/foo.jspx
You will need to use it by http://localhost:8080/projectName/jspx/foo.iface
you are all set.
Enjoy!
Develop Portlet (JSR168) with Icefaces
1. Add framework JSF in project properties.
Remember to uncheck library of JSF because we are using Icefaces.
2. In portlet.xml, change <portlet-class> to com.icesoft.faces.webapp.http.portlet.MainPortlet
3. In portlet.xml, add these in
<init-param> <name>com.icesoft.faces.VIEW</name> <value>/WEB-INF/jsp/view.iface</value> </init-param> <init-param> <name>com.icesoft.faces.EDIT</name> <value>/WEB-INF/jsp/edit.iface</value> </init-param> <init-param> <name>com.icesoft.faces.HELP</name> <value>/WEB-INF/jsp/help.iface</value> </init-param>
4. In web.xml
The ICEfaces Servlets are registered as follows:
<servlet>
<servlet-name>Persistent Faces Servlet</servlet-name>
<servlet-class>
com.icesoft.faces.webapp.xmlhttp.PersistentFacesServlet
</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>
<servlet>
<servlet-name>Blocking Servlet</servlet-name>
<servlet-class>
com.icesoft.faces.webapp.xmlhttp.BlockingServlet
</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>
The Servlet mappings are established as follows:
<servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.jspx</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Persistent Faces Servlet</servlet-name> <url-pattern>*.iface</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Persistent Faces Servlet</servlet-name> <url-pattern>/xmlhttp/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Blocking Servlet</servlet-name> <url-pattern>/block/*</url-pattern> </servlet-mapping> <listener> <listener-class> com.icesoft.faces.util.event.servlet.ContextEventRepeater </listener-class> </listener> <context-param> <param-name>com.icesoft.faces.concurrentDOMViews</param-name> <param-value>true</param-value> </context-param>
5. Sample .jspx for 1.7 beta
<f:view xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ice="http://www.icesoft.com/icefaces/component"> <html> <head> <title> ICEfaces Portlet Chat </title> </head> <body> <ice:portlet> <ice:outputStyle href="/xmlhttp/css/xp/xp-portlet.css" /> <f:loadBundle basename=" " var="bundle"/> <!-- Login/Logout --> <ice:form> <ice:outputText value="ICEFACES 1.7"/> </ice:form> </ice:portlet> </body> </html> </f:view>
For 1.6
Remove <ice:portlet>
Put <ice:outputStyle> inside <ice:form>