Facelets Çağatay Çivici Apache MyFaces PMC [email_address]
Çağatay Çivici <ul><li>Apache MyFaces Project PMC Member </li></ul><ul><li>OpenLogic Expert Group Member </li></ul><ul><li...
Agenda <ul><li>JSF and JSP </li></ul><ul><li>Facelets </li></ul><ul><li>Jsfc and inline texts </li></ul><ul><li>Templating...
JSF and JSP <ul><li>JSP is the default view technology </li></ul><ul><li>JSP tags refer to JSF components </li></ul><ul><u...
JSF and JSP (Advantages) <ul><li>JSP is well adopted, reduces learning curve of JSF. </li></ul><ul><li>Above is the only a...
JSF and JSP (Disadvantages) <ul><li>JSP is created to generate dynamic output not to create component trees </li></ul><ul>...
JSF and JSP <ul><li>JSF 1.1 - Initial request (e.g. index.jsf) </li></ul><ul><ul><li>FacesServlet gets the request and JSF...
Facelets <ul><li>A viewhandler purely created for JSF </li></ul><ul><li>No more JSP </li></ul><ul><li>.xhtml instead of .j...
Migrating from JSP to Facelets <ul><li><%@ taglib uri=&quot;http://java.sun.com/jsf/html&quot; prefix=&quot;h&quot;%> </li...
Installation <ul><li>Add jsf-facelets.jar to the classpath </li></ul><ul><li>Add viewhandler config to faces-config.xml </...
*.taglib.xml <ul><li>Concept similar to tld but lightweight </li></ul><ul><li>Used to define components, converters, valid...
Jsfc <ul><li>Jsfc :  jwcid  concepty in Tapestry </li></ul><ul><ul><li><h:commandButton id=“btn_save” value=“Save” action=...
Inline Texts <ul><li>Inline Text: Display texts without a UIComponent </li></ul><ul><ul><li><h:outputText value=“#{IndexPa...
Support for Unified EL <ul><li>Facelets support the Unified EL </li></ul><ul><li>#{BeanName.field} same as; </li></ul><ul>...
Templating <ul><li>A template is an xhtml with placeholders </li></ul><ul><li>Placeholders are marked with  ui:insert </li...
Composition Components <ul><li>Composition component is basically a template </li></ul><ul><li>userInfo.xhtml </li></ul><u...
EL Functions <ul><li>MyFunctions.java </li></ul><ul><ul><li>public   static  String length(String name) { </li></ul></ul><...
JSTL Support <ul><li>With JSP, mixing JSF and JSTL is problematic </li></ul><ul><li>Facelets brings limited but faultless ...
Custom logic tags <ul><li>JSTL like logic tags by extending Facelets TagHandler </li></ul><ul><li>myfacelets.taglib.xml </...
List of built-in Facelets tags <ul><li><ui:component/> </li></ul><ul><li><ui:composition/> </li></ul><ul><li>  <ui:debug/>...
Summary <ul><li>Facelets saves JSF from the burden of JSP </li></ul><ul><li>Great for templating and composition component...
The End – Questions? <ul><li>[email_address] </li></ul><ul><li>www.jroller.com/page/cagataycivici </li></ul>
Upcoming SlideShare
Loading in …5
×

Facelets

1,049
-1

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,049
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
26
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Facelets

  1. 1. Facelets Çağatay Çivici Apache MyFaces PMC [email_address]
  2. 2. Çağatay Çivici <ul><li>Apache MyFaces Project PMC Member </li></ul><ul><li>OpenLogic Expert Group Member </li></ul><ul><li>Sourceforge jsf-comp project developer </li></ul><ul><li>JSF Client Side Validators </li></ul><ul><li>Acegi Security Framework’s JSF Components </li></ul><ul><li>JFreeChart for JSF : JSF Chart Creator </li></ul><ul><li>FacesTrace: Visual Debugger of JSF </li></ul>
  3. 3. Agenda <ul><li>JSF and JSP </li></ul><ul><li>Facelets </li></ul><ul><li>Jsfc and inline texts </li></ul><ul><li>Templating </li></ul><ul><li>Composition Components </li></ul><ul><li>EL Functions </li></ul><ul><li>JSTL Support </li></ul><ul><li>Custom Logic Tags </li></ul>
  4. 4. JSF and JSP <ul><li>JSP is the default view technology </li></ul><ul><li>JSP tags refer to JSF components </li></ul><ul><ul><li>h:commandButton = HtmlCommandButton </li></ul></ul><ul><li>Mixing them brings overhead because of two different lifecycles </li></ul>
  5. 5. JSF and JSP (Advantages) <ul><li>JSP is well adopted, reduces learning curve of JSF. </li></ul><ul><li>Above is the only advantage  </li></ul>
  6. 6. JSF and JSP (Disadvantages) <ul><li>JSP is created to generate dynamic output not to create component trees </li></ul><ul><li>Two different lifecycles (overhead) </li></ul><ul><li>Content Interweaving Issues </li></ul>
  7. 7. JSF and JSP <ul><li>JSF 1.1 - Initial request (e.g. index.jsf) </li></ul><ul><ul><li>FacesServlet gets the request and JSF lifecycle begins </li></ul></ul><ul><ul><li>restoreState returns null and a new view is created ( createView ) with view id = index.jsp (jsp is the default suffix) </li></ul></ul><ul><ul><li>lifecycle jumps to renderResponse </li></ul></ul><ul><ul><li>renderView is called that dispatches index.jsp to the container </li></ul></ul><ul><ul><li>Container traverses all the tags, tags call component’s encode methods during component tree is created </li></ul></ul><ul><ul><li>State is saved via writeState and buffered output is rendered to the client. </li></ul></ul><ul><li>JSF 1.2 - a servletwrapper is used instead of f:view to buffer the content and component tree is created before rendering </li></ul>
  8. 8. Facelets <ul><li>A viewhandler purely created for JSF </li></ul><ul><li>No more JSP </li></ul><ul><li>.xhtml instead of .jsp </li></ul><ul><li>No tld files and no tag classes to defined a UIComponent </li></ul><ul><li>Faster than using JSP&JSF </li></ul>
  9. 9. Migrating from JSP to Facelets <ul><li><%@ taglib uri=&quot;http://java.sun.com/jsf/html&quot; prefix=&quot;h&quot;%> </li></ul><ul><li><%@ taglib uri=&quot;http://java.sun.com/jsf/core&quot; prefix=&quot;f&quot;%> </li></ul><ul><li><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; > </li></ul>
  10. 10. Installation <ul><li>Add jsf-facelets.jar to the classpath </li></ul><ul><li>Add viewhandler config to faces-config.xml </li></ul><ul><li>Change javax.faces.DEFAULT_SUFFIX to .xhtml </li></ul>
  11. 11. *.taglib.xml <ul><li>Concept similar to tld but lightweight </li></ul><ul><li>Used to define components, converters, validators, composition components, custom logic tags, functions and etc. </li></ul>
  12. 12. Jsfc <ul><li>Jsfc : jwcid concepty in Tapestry </li></ul><ul><ul><li><h:commandButton id=“btn_save” value=“Save” action=“#{bean.method}” /> </li></ul></ul><ul><ul><li><input jsfc=&quot;h:commandButton&quot; type=&quot;submit&quot; id=“ btn_save &quot; value=“ Save “ action=“#{bean.method}” /> </li></ul></ul><ul><li>Provides integration with HTML editors </li></ul>
  13. 13. Inline Texts <ul><li>Inline Text: Display texts without a UIComponent </li></ul><ul><ul><li><h:outputText value=“#{IndexPageBean.welcomeMessage}” /> </li></ul></ul><ul><ul><li><h1>#{IndexPageBean.welcomeMessage}</h1> </li></ul></ul>
  14. 14. Support for Unified EL <ul><li>Facelets support the Unified EL </li></ul><ul><li>#{BeanName.field} same as; </li></ul><ul><li>${BeanName.field} </li></ul>
  15. 15. Templating <ul><li>A template is an xhtml with placeholders </li></ul><ul><li>Placeholders are marked with ui:insert </li></ul><ul><ul><li>Fragment from Template.xhtml </li></ul></ul><ul><ul><li><title> </li></ul></ul><ul><ul><li><ui:insert name=&quot;title&quot;> Default Title </ui:insert> </li></ul></ul><ul><ul><li></title> </li></ul></ul><ul><li>In order to use the template ui:composition is needed. </li></ul><ul><ul><li>Fragment from index.xhtml </li></ul></ul><ul><ul><li><ui:composition template=&quot;/template.xhtml&quot;> </li></ul></ul><ul><ul><li><ui:define name=&quot;title&quot;> </li></ul></ul><ul><ul><li>Welcome to index page </li></ul></ul><ul><ul><li></ui:define> </li></ul></ul>
  16. 16. Composition Components <ul><li>Composition component is basically a template </li></ul><ul><li>userInfo.xhtml </li></ul><ul><ul><li><ui:composition xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot;> </li></ul></ul><ul><ul><li>< h3 > Logged as : #{ user }</ h3 > </li></ul></ul><ul><ul><li></ui:composition> </li></ul></ul><ul><li>myfacelets.taglib.xml </li></ul><ul><ul><li><tag> </li></ul></ul><ul><ul><li><tag-name> userInfo </tag-name> </li></ul></ul><ul><ul><li><source>tags/ userInfo .xhtml</source> </li></ul></ul><ul><ul><li></tag> </li></ul></ul><ul><li>Use as; </li></ul><ul><ul><li>< ds : userInfo user =&quot;#{ myBean . currentUser }&quot;/> </li></ul></ul>
  17. 17. EL Functions <ul><li>MyFunctions.java </li></ul><ul><ul><li>public static String length(String name) { </li></ul></ul><ul><ul><li>if ( name == null ) </li></ul></ul><ul><ul><li>return null ; </li></ul></ul><ul><ul><li>else </li></ul></ul><ul><ul><li>r eturn String. valueOf ( name.length() ); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>myfacelets.taglib.xml </li></ul><ul><ul><li><function> </li></ul></ul><ul><ul><li><function-name>length</function-name> </li></ul></ul><ul><ul><li><function-class>faceletsbox.utils.CustomerUtils</function-class> </li></ul></ul><ul><ul><li><function-signature> </li></ul></ul><ul><ul><li>java.lang.String length(java.lang.String) </li></ul></ul><ul><ul><li></function-signature> </li></ul></ul><ul><ul><li></function> </li></ul></ul><ul><li>Use as; </li></ul><ul><ul><li>#{ds:length(MyBean.userName)} </li></ul></ul>
  18. 18. JSTL Support <ul><li>With JSP, mixing JSF and JSTL is problematic </li></ul><ul><li>Facelets brings limited but faultless support </li></ul><ul><ul><li><c:if> </li></ul></ul><ul><ul><li><c:forEach> </li></ul></ul><ul><ul><li><c:catch> </li></ul></ul><ul><ul><li><c:set> </li></ul></ul>
  19. 19. Custom logic tags <ul><li>JSTL like logic tags by extending Facelets TagHandler </li></ul><ul><li>myfacelets.taglib.xml </li></ul><ul><ul><li><tag> </li></ul></ul><ul><ul><li><tag-name>if</tag-name> </li></ul></ul><ul><ul><li><handler-class> mycompany.myproject .utils.IfHandler</handler-class> </li></ul></ul><ul><ul><li></tag> </li></ul></ul><ul><li>Use as; </li></ul><ul><ul><li><ds:if test=&quot;#{MyBean.isLoggedIn}&quot;> </li></ul></ul><ul><ul><li>Welcome </li></ul></ul><ul><ul><li></ds:if> </li></ul></ul>
  20. 20. List of built-in Facelets tags <ul><li><ui:component/> </li></ul><ul><li><ui:composition/> </li></ul><ul><li>  <ui:debug/> </li></ul><ul><li>  <ui:decorate/> </li></ul><ul><li><ui:define/> </li></ul><ul><li><ui:fragment/> </li></ul><ul><li><ui:include/> </li></ul><ul><li><ui:insert/> </li></ul><ul><li><ui:param/> </li></ul><ul><li><ui:remove/> </li></ul><ul><li><ui:repeat/> </li></ul>
  21. 21. Summary <ul><li>Facelets saves JSF from the burden of JSP </li></ul><ul><li>Great for templating and composition components plus bonuses like el functions </li></ul><ul><li>IDE support is not wide, only Exadel support facelets for now </li></ul>
  22. 22. The End – Questions? <ul><li>[email_address] </li></ul><ul><li>www.jroller.com/page/cagataycivici </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×