Facelets Çağatay Çivici Apache MyFaces PMC
Çağatay Çivici Apache MyFaces Project PMC Member OpenLogic Expert Group Member Sourceforge jsf-comp project developer JSF Client Side Validators Acegi Security Framework’s 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
JSF and JSP JSP is the default view technology JSP tags refer to JSF components h:commandButton = HtmlCommandButton Mixing them brings overhead because of two different lifecycles
JSF and JSP (Advantages) JSP is well adopted, reduces learning curve of JSF. Above is the only advantage
JSF and JSP (Disadvantages) JSP is created to generate dynamic output not to create component trees Two different lifecycles (overhead) Content Interweaving Issues
JSF and JSP JSF Initial request (e.g. index.jsf) 1.FacesServlet gets the request and JSF lifecycle begins 2.restoreState returns null and a new view is created (createView) with view id = index.jsp (jsp is the default suffix) 3.lifecycle jumps to renderResponse 4.renderView is called that dispatches index.jsp to the container 5.Container traverses all the tags, tags call component’s encode methods during component tree is created 6.State is saved via writeState and buffered output is rendered to the client. JSF 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
Migrating from JSP to Facelets
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 Provides integration with HTML editors
Inline Texts Inline Text: Display texts without a UIComponent #{IndexPageBean.welcomeMessage}
Support for Unified EL Facelets support the Unified EL #{BeanName.field} same as; ${BeanName.field}
Templating A template is an xhtml with placeholders Placeholders are marked with ui:insert Fragment from Template.xhtml Default Title In order to use the template ui:composition is needed. Fragment from index.xhtml Welcome to index page
Composition Components Composition component is basically a template userInfo.xhtml Logged as : #{user} myfacelets.taglib.xml userInfo tags/userInfo.xhtml Use as;
EL Functions MyFunctions.java public static String length(String name) { if( name == null ) return null; else return String.valueOf( name.length() ); } myfacelets.taglib.xml length faceletsbox.utils.CustomerUtils java.lang.String length(java.lang.String) Use as; #{ds:length(MyBean.userName)}
JSTL Support With JSP, mixing JSF and JSTL is problematic Facelets brings limited but faultless support
Custom logic tags JSTL like logic tags by extending Facelets TagHandler myfacelets.taglib.xml if mycompany.myproject.utils.IfHandler Use as; Welcome
List of built-in Facelets tags
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
The End – Questions?