icefaces facelets integration - facelets to the rescue! ¢â‚¬¢ forcing...

Download ICEfaces Facelets Integration - Facelets to the Rescue! ¢â‚¬¢ Forcing XML-style JSP conventions was generally

Post on 11-Aug-2020

0 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

  • ICEfaces Facelets Integration

    ICESOFT TECHNOLOGIES INC. www.icefaces.org

  • Problems With JSP

    • Many of the features of JSF are designed to be pluggable/extendable, such as the “View Handler”

    • The default View Hander for JSF is designed for JavaServer Pages™ (JSP)

    • JSP is somewhat of a technology mismatch with JSF which places some limitations on developers

    ICESOFT TECHNOLOGIES INC. www.icefaces.org

    places some limitations on developers

  • Limitations With JSP

    • The original design decision made by the JSR-127 EG was to use JSP pages that contain XML syntax, for example:

  • Limitations With JSP (Cont.)

    • Using JSP in this manner made it difficult to mix JSF component markup with HTML. The Sun JSF 1.2 RI has made it easier, but with JSF 1.1, there is no guarantee that the
    tag in the following code is going to end up in the same location:

    ICESOFT TECHNOLOGIES INC. www.icefaces.org


  • Limitations With JSP (Cont.)

    • The workaround for this in JSF 1.1 is to surround HTML mark-up with the f:verbatim tag:

    ICESOFT TECHNOLOGIES INC. www.icefaces.org

    pageEncoding="UTF-8"/>


  • Facelets to the Rescue!

    • Forcing XML-style JSP conventions was generally not well received by developers

    • Inspired by an article by Hans Bergsten in June of 2004, Jacob Hookom, an independent software developer living in Eden Prairie, MN undertook the task of creating Facelets

    • Facelets is an alternative View Handler to JSP that removes

    ICESOFT TECHNOLOGIES INC. www.icefaces.org

    • Facelets is an alternative View Handler to JSP that removes the limitations of JSP and provides powerful templating and composite component features

  • Compare Facelets to JSP

    • The following Facelets XHTML markup is equivalent to the JSP markup from the previous slide:

    Hello
    World

    ICESOFT TECHNOLOGIES INC. www.icefaces.org

  • Facelets: Features

    • Entirely removes JSP from JSF

    • XHTML documents instead of JSP

    • Uses SAX XML parser to parse XHTML instead of Jasper JSP Compiler – When compared to JSP/Jasper:

    • Facelets view compiler creates a lighter-weight JSF component tree

    ICESOFT TECHNOLOGIES INC. www.icefaces.org

    • Facelets view compiler creates a lighter-weight JSF component tree

    • Approximately 30% faster at parsing and compiling pages

    • HTML elements become first-class JSF components

    • Templating feature created specifically for JSF

    • Composite Components

  • Facelets: Features (Cont.)

    • Enhanced error reporting during development • Live development of JSF views • JSF EL value bindings can exist anywhere on the page

    – Bean values can be placed in a page without using JSF component binding

    • New tag library with a handful of components: – – –

    ICESOFT TECHNOLOGIES INC. www.icefaces.org

    – – –

    • Dynamic Includes – Dynamically insert and remove components from the component tree using

    – Can reduces memory overhead of large component trees

  • Facelets: The Future of JSF

    • Facelets will become the premier view handler technology for JSF 2.0 – JSP support in JSF could possibly be deprecated or dropped

    • Many new composite component features

    • The best of Ken Paulsen’s JSF Templating will be incorporated into Facelets

    ICESOFT TECHNOLOGIES INC. www.icefaces.org

    incorporated into Facelets

  • ICEfaces + Facelets Configuration

    • Register D2DFaceletViewHander in faces-config.xml

    • Register optional facelets.DEVELOPMENT in web.xml

    • Additional Required Libraries: – icefaces-facelets.jar

    – el-api.jar (Tomcat 5.5 only)

    – el-ri.jar (Tomcat 5.5 only)

    ICESOFT TECHNOLOGIES INC. www.icefaces.org

    – el-ri.jar (Tomcat 5.5 only)

    • Register javax.faces.DEFAULT_SUFFIX as .xhtml in web.xml

  • IDE Support

    • In the past, IDE support for Facelets has been weak

    • Today, MyEclipse 6.5 has full support for Facelets – Auto-complete in text editor

    – JSF components available on a palette

    – Design time view

    • JBoss IDE (Eclipse) has full support for Facelets – Note that ICEfaces plugin is not available for JBoss IDE

    • NetBeans 6.1 has improved support for Facelets – Auto-complete in text editor

    ICESOFT TECHNOLOGIES INC. www.icefaces.org

    – Auto-complete in text editor

    – JSF components not available on a palette – No design time view

    • Eclipse 3.3 (Europa) and 3.4 (Ganymede) have limited support for Facelets – No auto-complete in text editor (3.3)

    – JSF components available on a palette – Properties view shows possible attribute names and values

    – Design time view available with Web Page Editor

    • Sometimes IDEs can be tricked into supporting Facelets by using .jspx file extensions with inside the file

  • Facelets is Not JSP

    • Cannot use JSP taglib, so need to remove these tags: –

    • JSP tags will be ignored and passed through to the browser

    ICESOFT TECHNOLOGIES INC. www.icefaces.org

    • JSP tags will be ignored and passed through to the browser

    • You can however use a subset of JSTL tags with Facelets, including: –

    – - exception handling

  • ICEfaces and Facelets

    • In a standard JSF web application, Facelets is provided in the jsf-facelets.jar file

    • ICEfaces ships with a file named icefaces-facelets.jar which fixes a few bugs that interfere with the integration of ICEfaces and Facelets

    ICESOFT TECHNOLOGIES INC. www.icefaces.org

  • Facelets: Templating

    • Provides an intuitive mechanism for defining logical areas of the page

    • Can be used to separate layout from data input/output

    • Logical areas of a page are defined using a

    • Default content can be added as child elements to a

    ICESOFT TECHNOLOGIES INC. www.icefaces.org

    • Default content can be added as child elements to a defined

    • JSF pages that implement a template define the named include areas

    • If a named insert is not implemented then the default values will be rendered

  • Facelets: Templating (Cont.)

    • Terms: – Template: page used as a layout controller

    – Template-client: page that uses a template to layout it’s own content

    • URL is directed to template-client

    • Template-client declares which template to use

    ICESOFT TECHNOLOGIES INC. www.icefaces.org

    • Template-client declares which template to use

    • Template-client defines the content to be used by the template with – Path references in templates are resolved from the path location of

    the template-client

  • Facelets: Composite Components

    • The JSF spec requires components to be written as Java classes

    • Facelets addresses the developer's need for creating reusable JSF components that are composed with a combination of HTML and JSF markup

    – Allows for the reuse and naming of a collection of other components

    – Defined with XHTML markup, so there is no Java classes or renderer to write!

    ICESOFT TECHNOLOGIES INC. www.icefaces.org

    write!

    • Composite components are essentially templates which have been associated with a custom tag library

    • Referencing composite components in other JSF views is as simple as importing the namespace

  • Facelets: Composite Components (Cont.)

    • Consider the following markup, which is extremely verbose:

    ICESOFT TECHNOLOGIES INC. www.icefaces.org

    • With many columns in a table, the XHTML page becomes unnecessarily large

    • Wouldn't it be nice too somehow encapsulate this code for reuse? With facelets, we can!

  • Facelets: Composite Components (Cont.)

    • Question: How can we turn this:

    ICESOFT TECHNOLOGIES INC. www.icefaces.org

    • Into one line of code, like this?

    • Answer: create a facelets tag library and zip it up into a .jar file

  • Facelets Templating

    ICESOFT TECHNOLOGIES INC. www.icefaces.org

  • Overview

    • The goal of this example is to demonstrate the Facelets templating feature

    • The following Facelets tags will be used to build a simple, reusable template:

    – ui:composition

    – ui:decorate

    – ui:define

    ICESOFT TECHNOLOGIES INC. www.icefaces.org

    – ui:define

    – ui:include

  • Step 1: Creation of Templates

    • Templates and JSP fragments are usually stored in a the protected WEB-INF folder to avoid accidental loading.

    • Create the following folder structure in the jobApplication or another icefaces ready project:

    web/WEB-INF/includes/templates

    web/WEB-INF/includes/content

    ICESOFT TECHNOLOGIES INC. www.icefaces.org

    web/WEB-INF/includes/content

    web/css/

    Copy the content from the respective starter directories and copy facelets

Recommended

View more >