Académique Documents
Professionnel Documents
Culture Documents
aatay ivici
Apache MyFaces Project PMC Member OpenLogic Expert Group Member Sourceforge jsf-comp project developer JSF Client Side Validators Acegi Security Frameworks JSF Components JFreeChart for JSF : JSF Chart Creator FacesTrace: Visual Debugger of JSF
Agenda
JSF and JSP Facelets Jsfc and inline texts Templating Composition Components EL Functions JSTL Support Custom Logic Tags
FacesServlet gets the request and JSF lifecycle begins restoreState returns null and a new view is created (createView) with view id = index.jsp (jsp is the default suffix) lifecycle jumps to renderResponse renderView is called that dispatches index.jsp to the container Container traverses all the tags, tags call components encode methods during component tree is created State is saved via writeState and buffered output is rendered to the client.
JSF 1.2 - a servletwrapper is used instead of f:view to buffer the content and component tree is created before rendering
Facelets
A viewhandler purely created for JSF No more JSP .xhtml instead of .jsp No tld files and no tag classes to defined a UIComponent Faster than using JSP&JSF
Installation
Add jsf-facelets.jar to the classpath Add viewhandler config to faces-config.xml Change javax.faces.DEFAULT_SUFFIX to .xhtml
*.taglib.xml
Concept similar to tld but lightweight Used to define components, converters, validators, composition components, custom logic tags, functions and etc.
Jsfc
Jsfc : jwcid concepty in Tapestry
<h:commandButton id=btn_save value=Save action=#{bean.method} /> <input jsfc="h:commandButton" type="submit" id=btn_save" value=Save action=#{bean.method}/>
Inline Texts
Inline Text: Display texts without a UIComponent
<h:outputText value=#{IndexPageBean.welcomeMessage} /> <h1>#{IndexPageBean.welcomeMessage}</h1>
Templating
A template is an xhtml with placeholders Placeholders are marked with ui:insert
Fragment from Template.xhtml <title> <ui:insert name="title">Default Title</ui:insert> </title>
Composition Components
Composition component is basically a template userInfo.xhtml
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"> <h3>Logged as : #{user}</h3> </ui:composition>
myfacelets.taglib.xml
<tag>
<tag-name>userInfo</tag-name> <source>tags/userInfo.xhtml</source> </tag>
Use as;
<ds:userInfo user="#{myBean.currentUser}"/>
EL Functions
MyFunctions.java
public static String length(String name) { if( name == null ) return null; else return String.valueOf( name.length() );
myfacelets.taglib.xml
<function> <function-name>length</function-name> <function-class>faceletsbox.utils.CustomerUtils</function-class> <function-signature> java.lang.String length(java.lang.String) </function-signature> </function>
Use as;
#{ds:length(MyBean.userName)}
JSTL Support
With JSP, mixing JSF and JSTL is problematic Facelets brings limited but faultless support
<c:if> <c:forEach> <c:catch> <c:set>
Use as;
<ds:if test="#{MyBean.isLoggedIn}"> Welcome </ds:if>
Summary
Facelets saves JSF from the burden of JSP Great for templating and composition components plus bonuses like el functions IDE support is not wide, only Exadel support facelets for now