Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Facelets Çağatay Çivici Apache MyFaces Team Member Slightly modified by Sang Shin

Similar presentations


Presentation on theme: "1 Facelets Çağatay Çivici Apache MyFaces Team Member Slightly modified by Sang Shin"— Presentation transcript:

1 1 Facelets Çağatay Çivici Apache MyFaces Team Member cagatay@apache.org Slightly modified by Sang Shin sang.shin@sun.com

2 2 Agenda  Issues of using JSP with JSF  Facelets  Jsfc and inline texts  Templating  Composition Components  EL Functions  JSTL Support  Custom Logic Tags

3 3 Issues of Using JSP with JSF

4 4 JSF and JSP  JSP is the default view technology in JSF  JSP tags refer to JSF components h:commandButton = HtmlCommandButton  Mixing them brings overhead because of two different lifecycles

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

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

7 7 JSF and JSP  JSF 1.1 - 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 1.2 - a servletwrapper is used instead of f:view to buffer the content and component tree is created before rendering

8 8 What is & Why Facelets?

9 9 Why Facelets?  Provides an alternative view technology for building JSF applications Solves JSP/JSF mismatch problem Facelets' View handler is specifically designed for JSF  JSP does not have to be used Uses XHTML instead Does not require Web container

10 10 Why Facelets?  Provides powerful templating system Allows you to define JSF views using HTML-style templates Reduces the amount of code necessary to integrate components into the view  Web application framework independent Works with Struts, JSF, Spring MVC, Portlet, etc.

11 11 Why Facelets?  Provides simpler tag development Does not require complex JSP tag development - No tld files and no tag classes to define a UIComponent

12 12 Why Facelets?  Designer and developer friendly Designers can use HTML designer tools such as Dreamweaver  JSF tags such as or will not work well with HTML designer

13 13 Why Facelets?  Faster than using JSP&JSF No need to translate JSP pages into Servlet, which are then need to be compiled Instead Facelets XML files are parsed, which are faster

14 14 How to Use Facelets?

15 15 Migrating from JSP to Facelets  

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

17 17 Aliasing Components though jsfc

18 18 Why jsfc?  Everyone wants to be more designer friendly, and Tapestry seems to be the only choice developers are pursuing.  On the other hand, JSF is the standard everyone would like to have happen, but JSF needs a more "pluggable" ViewHandler framework that is both designer and developer friendly.

19 19 jsfc  Similar to jwcid concept in Tapestry Lets designers use plain old HTML tags  Faceslets compiler convert HTML elements to their associated JSF component  Example – JSP approach  Example – Facelets approach  Provides integration with HTML editors

20 20 Example <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:c="http://java.sun.com/jstl/core"> Hello Hi. My name is Duke. I'm thinking of a number from #{UserNumberBean.minimum} to #{UserNumberBean.maximum}. Can you guess it? <input type="text" jsfc="h:inputText" id="userNo" value="#{UserNumberBean.userNumber}" validator="#{UserNumberBean.validate}"/> <input type="submit" jsfc="h:commandButton" id="submit" action="success" value="Submit" />

21 21 Example #{view.viewId} #{v.index}

22 22 Inline Texts  Inline Text: Display texts without a UIComponent #{IndexPageBean.welcomeMessage}

23 23 Templating

24 24 Facelets Templating  Provides powerful templating system that enables you to define JSF views using HTML-style templates  Reduces the amount of code necessary to integrate components into the view  Enhances reusability  Doesn't require a web container

25 25 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

26 26 Composition

27 27 Facelets Composition  Allows reuse of contents in the web pages  Example Maybe there's a series of form controls or a complex menu that you would rather separate out into a different document that can be reused or managed separately without cluttering up your page layout

28 28 Composition Components  Composition component is basically a template  userInfo.xhtml Logged as : #{user}  myfacelets.taglib.xml userInfo tags/userInfo.xhtml  Use as;

29 29 *.taglib.xml

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

31 31 EL Functions

32 32 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)}

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

34 34 JSTL Support

35 35 JSTL Support  With JSP, mixing JSF and JSTL could be problematic  Facelets brings limited but faultless support

36 36 Custom Logic Tags

37 37 Custom logic tags  JSTL like logic tags by extending Facelets TagHandler  myfacelets.taglib.xml if mycompany.myproject.utils.IfHandler  Use as; Welcome

38 38 List of built-in Facelets tags 

39 39 Using 3rd-party Components in JSF + Facelets

40 40 Summary

41 41 Summary  Facelets saves JSF from the burden of JSP  Great for templating and composition components plus bonuses like el functions  IDE support is coming Exadel support facelets NetBeans Facelets plug-in

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


Download ppt "1 Facelets Çağatay Çivici Apache MyFaces Team Member Slightly modified by Sang Shin"

Similar presentations


Ads by Google