facelets
TRANSCRIPT
![Page 2: Facelets](https://reader033.vdocument.in/reader033/viewer/2022051616/5562d92ad8b42aac778b4c7a/html5/thumbnails/2.jpg)
Ç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
![Page 3: Facelets](https://reader033.vdocument.in/reader033/viewer/2022051616/5562d92ad8b42aac778b4c7a/html5/thumbnails/3.jpg)
Agenda JSF and JSP Facelets Jsfc and inline texts Templating Composition Components EL Functions JSTL Support Custom Logic Tags
![Page 4: Facelets](https://reader033.vdocument.in/reader033/viewer/2022051616/5562d92ad8b42aac778b4c7a/html5/thumbnails/4.jpg)
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
![Page 5: Facelets](https://reader033.vdocument.in/reader033/viewer/2022051616/5562d92ad8b42aac778b4c7a/html5/thumbnails/5.jpg)
JSF and JSP (Advantages)
JSP is well adopted, reduces learning curve of JSF.
Above is the only advantage
![Page 6: Facelets](https://reader033.vdocument.in/reader033/viewer/2022051616/5562d92ad8b42aac778b4c7a/html5/thumbnails/6.jpg)
JSF and JSP (Disadvantages)
JSP is created to generate dynamic output not to create component trees
Two different lifecycles (overhead) Content Interweaving Issues
![Page 7: Facelets](https://reader033.vdocument.in/reader033/viewer/2022051616/5562d92ad8b42aac778b4c7a/html5/thumbnails/7.jpg)
JSF and JSP JSF 1.1 - Initial request (e.g. index.jsf)
1. FacesServlet gets the request and JSF lifecycle begins2. restoreState returns null and a new view is created (createView)
with view id = index.jsp (jsp is the default suffix)3. lifecycle jumps to renderResponse4. renderView is called that dispatches index.jsp to the container5. Container traverses all the tags, tags call component’s encode
methods during component tree is created6. 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
![Page 8: Facelets](https://reader033.vdocument.in/reader033/viewer/2022051616/5562d92ad8b42aac778b4c7a/html5/thumbnails/8.jpg)
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
![Page 9: Facelets](https://reader033.vdocument.in/reader033/viewer/2022051616/5562d92ad8b42aac778b4c7a/html5/thumbnails/9.jpg)
Migrating from JSP to Facelets <%@ taglib uri="http://java.sun.com/jsf/html"
prefix="h"%> <%@ taglib uri="http://java.sun.com/jsf/core"
prefix="f"%>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core">
![Page 10: Facelets](https://reader033.vdocument.in/reader033/viewer/2022051616/5562d92ad8b42aac778b4c7a/html5/thumbnails/10.jpg)
Installation Add jsf-facelets.jar to the classpath Add viewhandler config to faces-config.xml Change javax.faces.DEFAULT_SUFFIX to .xhtml
![Page 11: Facelets](https://reader033.vdocument.in/reader033/viewer/2022051616/5562d92ad8b42aac778b4c7a/html5/thumbnails/11.jpg)
*.taglib.xml
Concept similar to tld but lightweight Used to define components,
converters, validators, composition components, custom logic tags, functions and etc.
![Page 12: Facelets](https://reader033.vdocument.in/reader033/viewer/2022051616/5562d92ad8b42aac778b4c7a/html5/thumbnails/12.jpg)
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}”/>
Provides integration with HTML editors
![Page 13: Facelets](https://reader033.vdocument.in/reader033/viewer/2022051616/5562d92ad8b42aac778b4c7a/html5/thumbnails/13.jpg)
Inline Texts Inline Text: Display texts without a
UIComponent <h:outputText
value=“#{IndexPageBean.welcomeMessage}” /> <h1>#{IndexPageBean.welcomeMessage}</h1>
![Page 14: Facelets](https://reader033.vdocument.in/reader033/viewer/2022051616/5562d92ad8b42aac778b4c7a/html5/thumbnails/14.jpg)
Support for Unified EL
Facelets support the Unified EL #{BeanName.field} same as; ${BeanName.field}
![Page 15: Facelets](https://reader033.vdocument.in/reader033/viewer/2022051616/5562d92ad8b42aac778b4c7a/html5/thumbnails/15.jpg)
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>
In order to use the template ui:composition is needed. Fragment from index.xhtml <ui:composition template="/template.xhtml">
<ui:define name="title">Welcome to index page
</ui:define>
![Page 16: Facelets](https://reader033.vdocument.in/reader033/viewer/2022051616/5562d92ad8b42aac778b4c7a/html5/thumbnails/16.jpg)
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}"/>
![Page 17: Facelets](https://reader033.vdocument.in/reader033/viewer/2022051616/5562d92ad8b42aac778b4c7a/html5/thumbnails/17.jpg)
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)}
![Page 18: Facelets](https://reader033.vdocument.in/reader033/viewer/2022051616/5562d92ad8b42aac778b4c7a/html5/thumbnails/18.jpg)
JSTL Support
With JSP, mixing JSF and JSTL is problematic
Facelets brings limited but faultless support <c:if> <c:forEach> <c:catch> <c:set>
![Page 19: Facelets](https://reader033.vdocument.in/reader033/viewer/2022051616/5562d92ad8b42aac778b4c7a/html5/thumbnails/19.jpg)
Custom logic tags
JSTL like logic tags by extending Facelets TagHandler
myfacelets.taglib.xml <tag>
<tag-name>if</tag-name><handler-class>mycompany.myproject.utils.IfHandler</handler-
class></tag>
Use as; <ds:if test="#{MyBean.isLoggedIn}">
Welcome</ds:if>
![Page 20: Facelets](https://reader033.vdocument.in/reader033/viewer/2022051616/5562d92ad8b42aac778b4c7a/html5/thumbnails/20.jpg)
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/>
![Page 21: Facelets](https://reader033.vdocument.in/reader033/viewer/2022051616/5562d92ad8b42aac778b4c7a/html5/thumbnails/21.jpg)
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