• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Facelets
 

Facelets

on

  • 1,178 views

 

Statistics

Views

Total Views
1,178
Views on SlideShare
1,177
Embed Views
1

Actions

Likes
0
Downloads
24
Comments
0

1 Embed 1

http://www.slideshare.net 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Facelets Facelets Presentation Transcript

    • Facelets Çağatay Çivici Apache MyFaces PMC [email_address]
    • Ç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 1.1 - Initial request (e.g. index.jsf)
        • 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 component’s 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
    • Migrating from JSP to Facelets
      • <%@ taglib uri=&quot;http://java.sun.com/jsf/html&quot; prefix=&quot;h&quot;%>
      • <%@ taglib uri=&quot;http://java.sun.com/jsf/core&quot; prefix=&quot;f&quot;%>
      • <html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xmlns:h=&quot;http://java.sun.com/jsf/html&quot; xmlns:f=&quot;http://java.sun.com/jsf/core&quot; >
    • 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=&quot;h:commandButton&quot; type=&quot;submit&quot; id=“ btn_save &quot; value=“ Save “ action=“#{bean.method}” />
      • Provides integration with HTML editors
    • Inline Texts
      • Inline Text: Display texts without a UIComponent
        • <h:outputText value=“#{IndexPageBean.welcomeMessage}” />
        • <h1>#{IndexPageBean.welcomeMessage}</h1>
    • 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
        • <title>
        • <ui:insert name=&quot;title&quot;> Default Title </ui:insert>
        • </title>
      • In order to use the template ui:composition is needed.
        • Fragment from index.xhtml
        • <ui:composition template=&quot;/template.xhtml&quot;>
        • <ui:define name=&quot;title&quot;>
        • Welcome to index page
        • </ui:define>
    • Composition Components
      • Composition component is basically a template
      • userInfo.xhtml
        • <ui:composition xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot;>
        • < 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 =&quot;#{ myBean . currentUser }&quot;/>
    • EL Functions
      • MyFunctions.java
        • public static String length(String name) {
        • if ( name == null )
        • return null ;
        • else
        • r eturn 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>
    • 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=&quot;#{MyBean.isLoggedIn}&quot;>
        • Welcome
        • </ds:if>
    • 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/>
    • 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?
      • [email_address]
      • www.jroller.com/page/cagataycivici