JavaServer Faces technology is a framework for building

Download Report

Transcript JavaServer Faces technology is a framework for building

JSF Introduction
Copyright © 2000-2007 Liferay, Inc.
All Rights Reserved.
No material may be reproduced electronically or in print without written
permission from Liferay, Inc.
Objective
The goal of this tutorial is to create a Java
Server Faces (JSF) Portlet within Liferay
1. What is JSF?
2. Why JSF vs. Struts?
Key Concepts
What are the main differences between a
JSF Portlet and a JSP Portlet?
– JSF follows the MVC pattern, and provides a
framework to develop robust web applications
– JSP is a model 1 pattern; good for rapid
prototyping
What is JSF?
JavaServer Faces technology is a framework for
building user interfaces for web applications.
JavaServer Faces technology includes:
• A set of APIs for: representing UI components and
managing their state, handling events and input
validation, defining page navigation, and supporting
internationalization and accessibility.
• A JavaServer Pages (JSP) custom tag library for
expressing a JavaServer Faces interface within a JSP
page.”
Reference: Sun Developer Network. JavaServer Faces Technology FAQ. http://java.sun.com/javaee/javaserverfaces/reference/faqs/index.html
What are the benefits of JSF?
•
Container Agnostic
Development is the same whether your application is servlet or portlet based
•
Tree-based Component Model
All components on the JSP page (JSF tags) are persisted in memory
This gives you the ability to insert a table or a button in the middle of a page at
runtime rather than code it in your JSP. Elements on the page can be traversed in
the POJO.
•
Enforces Best Practices
Everything is encapsulated in a component. Consistent development means that
the code is easier to maintain.
•
Highly Customizable
Every level of the JSF life cycle is customizable. For example, JSF is not tied to a
presentation layer and does not have to use the HTTP protocol.
What are the key differences
between JSF and Struts?
Struts is an open-source Java web application framework whose
architecture is based on the Model-View-Controller design
pattern in which requests are routed through a controller that
provides overall application management and dispatches the
requests to application components.
JavaServer Faces technology is a user-interface framework for
Java web applications. It is focused on the view tier of an MVCbased architecture.
The Struts and JavaServer Faces technology frameworks do have
some overlapping functionality; however each framework has
its advantages, and developers can use certain features of both
frameworks in a single application.
Reference: Sun Developer Network. JavaServer Faces Technology FAQ. http://java.sun.com/javaee/javaserverfaces/reference/faqs/index.html
Advantages of JSF over Struts
The main advantage of JSF is its flexible, extensible UI component
model which includes:
A standard component API for specifying the state and behavior of a
wide range of components, including simple components, such as
input fields, and more complex components, such as scrollable
data tables.
A separate rendering model that defines how to render the components
in various ways. For example, a component used for selecting an
item from a list can be rendered as a menu or a set of radio
buttons.
An event and listener model that defines how to handle events
generated by activating a component, such as what to do when a
user clicks a button.
Reference: Sun Developer Network. JavaServer Faces Technology FAQ. http://java.sun.com/javaee/javaserverfaces/reference/faqs/index.html
JavaServer Faces separates the definition of a component from its
rendering, so you can render your components in different ways
or even to different clients, such as a WML client.
JavaServer Faces technology allows you to extend the standard set of
components and create entirely new components.
Struts has no notion of server-side components, which means that it
has no event model for responding to component events and no
facility for saving and restoring component state. While Struts
does have a useful tag library for rendering components on the
page, these components have no object representation on the
server and they can only be rendered to an HTML client.
The controller logic is implemented in POJOs so there is no need to
implement Struts’ processAction or execute methods.
JSF provides tags that specify which method will be called, further
simplifying the controller logic. <h:commandButton
action="#{myBean.addBook}"> calls myBean.addBook()
Reference: Sun Developer Network. JavaServer Faces Technology FAQ. http://java.sun.com/javaee/javaserverfaces/reference/faqs/index.html
Revision History
Edward Shin
James Min
8/28/2006 Updated for Liferay 4.1.1
01/17/2007 4.2.1