Çağatay Çivici Apache MyFaces PMC cagatay@apache.org

Ç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 .

 Above is the only advantage . reduces learning curve of JSF.JSF and JSP (Advantages)  JSP is well adopted.

JSF and JSP (Disadvantages)  JSP is created to generate dynamic output not to create component trees  Two different lifecycles (overhead)  Content Interweaving Issues .

Initial request (e. 2.a servletwrapper is used instead of f:view to buffer the content and component tree is created before rendering . index. 6. 5.jsf) 1. 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.g.  JSF 1. tags call component’s encode methods during component tree is created State is saved via writeState and buffered output is rendered to the client.jsp to the container Container traverses all the tags. 3.2 . 4.JSF and JSP  JSF 1.1 .

Facelets A viewhandler purely created for JSF No more JSP .jsp No tld files and no tag classes to defined a UIComponent  Faster than using JSP&JSF     .xhtml instead of .

com/jsf/core" prefix="f"%>  <html xmlns="http://www.com/jsf/core"> .sun.com/jsf/html" xmlns:f="http://java.com/jsf/html" prefix="h"%> <%@ taglib uri="http://java.org/1999/xhtml" xmlns:h="http://java.Migrating from JSP to Facelets  <%@ taglib uri="http://java.sun.w3.sun.sun.

xhtml .jar to the classpath  Add viewhandler config to faces-config.xml  Change javax.faces.DEFAULT_SUFFIX to .Installation  Add jsf-facelets.

xml  Concept similar to tld but lightweight  Used to define components. converters. validators. . custom logic tags.*. composition components. functions and etc.taglib.

method}” /> <input jsfc="h:commandButton" type="submit" id=“btn_save" value=“Save“ action=“#{bean.method}”/>  Provides integration with HTML editors .Jsfc  Jsfc : jwcid concepty in Tapestry   <h:commandButton id=“btn_save” value=“Save” action=“#{bean.

welcomeMessage}” /> <h1>#{IndexPageBean.Inline Texts  Inline Text: Display texts without a UIComponent   <h:outputText value=“#{IndexPageBean.welcomeMessage}</h1> .

field} same as.  ${BeanName.field} .Support for Unified EL  Facelets support the Unified EL  #{BeanName.

xhtml <ui:composition template="/template.xhtml <title> <ui:insert name="title">Default Title</ui:insert> </title>  In order to use the template ui:composition is needed.Templating  A template is an xhtml with placeholders  Placeholders are marked with ui:insert   Fragment from Template.   Fragment from index.xhtml"> <ui:define name="title"> Welcome to index page </ui:define> .

com/jsf/facelets"> <h3>Logged as : #{user}</h3> </ui:composition>  myfacelets.  <ds:userInfo user="#{myBean.sun.xhtml</source> </tag>  Use as.xhtml  <ui:composition xmlns:ui="http://java.xml  <tag> <tag-name>userInfo</tag-name> <source>tags/userInfo.currentUser}"/> .taglib.Composition Components  Composition component is basically a template  userInfo.

utils.taglib.CustomerUtils</function-class> <function-signature> java.  #{ds:length(MyBean.EL Functions  MyFunctions.String length(java.length() ).lang. else return String.valueOf( name.xml  <function> <function-name>length</function-name> <function-class>faceletsbox.lang. }  myfacelets.String) </function-signature> </function>  Use as.userName)} .java  public static String length(String name) { if( name == null ) return null.

JSTL Support  With JSP. mixing JSF and JSTL is problematic  Facelets brings limited but faultless support     <c:if> <c:forEach> <c:catch> <c:set> .

isLoggedIn}"> Welcome </ds:if> .myproject.taglib.utils.  <ds:if test="#{MyBean.IfHandler</handler-class> </tag>  Use as.xml  <tag> <tag-name>if</tag-name> <handler-class>mycompany.Custom logic tags  JSTL like logic tags by extending Facelets TagHandler  myfacelets.

List of built-in Facelets tags            <ui:component/> <ui:composition/> <ui:debug/> <ui:decorate/> <ui:define/> <ui:fragment/> <ui:include/> <ui:insert/> <ui:param/> <ui:remove/> <ui:repeat/> .

only Exadel support facelets for now .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.

org  www.com/page/cagataycivici .jroller.The End – Questions?  cagatay@apache.

Sign up to vote on this title
UsefulNot useful