javaserver faces n.
Skip this Video
Loading SlideShow in 5 Seconds..
JavaServer Faces PowerPoint Presentation
Download Presentation
JavaServer Faces

Loading in 2 Seconds...

play fullscreen
1 / 40

JavaServer Faces - PowerPoint PPT Presentation

  • Uploaded on

JavaServer Faces. Presented by: Jim O’Hara Ed Kausmeyer Jingming Zhang. Introducing JavaServer Faces (JSF). New and upcoming web application framework for building user interfaces (UI’s) for web applications For building server-side UI’s

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'JavaServer Faces' - alva

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
javaserver faces

JavaServer Faces

Presented by:

Jim O’Hara

Ed Kausmeyer

Jingming Zhang

introducing javaserver faces jsf
Introducing JavaServer Faces (JSF)
  • New and upcoming web application framework for building user interfaces (UI’s) for web applications
  • For building server-side UI’s
  • Accomplishes the Model-View-Controller (MVC) paradigm
  • Designed to be flexible and easy to use
  • Leverages existing standard UI and web-tier concepts without limiting developers to a particular mark-up language, protocol, or client device
  • Comparable to the well-known Struts Framework
    • Features and concepts that are beyond those of Struts, especially the component orientation
introducing javaserver faces jsf1
Introducing JavaServer Faces (JSF)
  • 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 JSF interface within a JSP page
    • JSF version 1.0 relies on JSP 1.2
    • Since JSP 2.0 is a superset of JSP 1.2, it is possible to use JSF 1.0 with JSP 2.0
    • Future versions of the JSF specification will be able to take better advantage of JSP 2.0
standardization of jsf
Standardization of JSF
  • JavaServer Faces Developer Forum:
  • JSF APIs are being designed so that they can be leveraged by tools that will make web application development even easier
  • Developed through the Java Community Process under JSR-127
    • JSRs: Java Specification Requests
    • JSR-127:
    • JSR-252:
  • A number of important industry players are collaborating with Sun to develop the JSF specification
    • Many prominent tool vendors are part of the expert group and are committed to supporting the JSF technology in their tools, thus promoting the adoption of the JSF technology standard
jsf user interfaces
JSF User Interfaces
  • A UI created with JSF handles all the complexities of UI management
    • Input validation, component-state management, page navigation, and event handling
  • The UI component classes encapsulate the component functionality, not the client-specific presentation
    • UI components can be rendered to various client devices
    • Renderers: define rendering attributes for a specific UI component
jsf user interfaces1
JSF User Interfaces
  • By combining the UI component functionality with custom renderers, developers can construct custom tags to a particular client device
    • Device Independence: By defining only component functionality in extensible UI component classes, JSF allows component developers to extend the component classes to generate their own component tag libraries targeted for specific clients
  • JSF provides a custom renderer and a JSP custom tag library for rendering to an HTML client
    • Allows developers of Java 2 Platform, Enterprise Edition (J2EE) applications to use JSF technology in their applications
benefits of the jsf design
Benefits of the JSF Design
  • The JSF architecture clearly defines a separation between application logic and presentation while making it easy to connect the presentation layer to the application code
  • With this simple, well-defined programming model, developers of varying skill levels can quickly and easily build Web applications by assembling reusable UI components in a page, connecting these components to an application data source, and wiring client-generated events to server-side event handlers
benefits of the jsf design1
Benefits of the JSF Design
  • These web applications handle all of the complexity of managing the UI on the server, allowing each member of a web application development team to focus on their piece of the development process (i.e., their application code)
    • Allows a wide range of users, from web-page designers to component developers, to take advantage of JSF
      • Example: Web page developers with no programming expertise can use JSF UI component tags to link to application code from within a web page without writing any scripts
    • Division of labor, shorter development cycle
benefits of the jsf design2
Benefits of the JSF Design
  • How various developers and web-page designers can take advantage of JSF's extensibility, ease-of-use, and capabilities:
    • Page Authors
      • Build the UI using component tags from within web pages, such as JSP pages
      • Probably the primary users of the JSF custom tag library
    • Application Developers
      • Write the application code, including the data-access, event-handling, and business logic
    • Component Writers
      • Construct reusable UI components
      • Take advantage of the extensibility of the UI component classes to build custom components that can be targeted for a specific client
    • Tools Vendors
      • Build tools leveraging JSF technology to make building a UI even easier
jsf and mvc


JavaServer Faces (JSF) technology is a new user interface framework for J2EE applications. It is particularly suited, by design, for use with applications based on the MVC (Model-View-Controller) architecture.

mvc model view controller
  • MVC was first described by Xerox in a number of papers published in the late 1980s, in conjunction with the Smalltalk language. This model has since been used for GUI applications developed in all popular programming languages.
  • The basic idea is to separate the application data and business logic, the presentation of the data, and the interaction with the data into distinct entities labeled the Model, the View, and the Controller, respectively.
the mvc design pattern splits an application design into three separate parts
The MVC design pattern splits an application design into three separate parts:
  • The Model handles data and logic. Model code accesses and represents data, and handles business operations. "Business operations" include changes to both persistent business data, and to things like shopping cart contents
  • The View handles output. View code displays data to the user.
  • The Controller handles input. Controller code manipulates the Model or changes the view accordingly in response to user input (the Controller can also do both).
these parts have specific relationships to one another
These parts have specific relationships to one another:
  • The View accesses the Model to retrieve data for display.
  • The Controller receives user input, and makes business method invocations on the Model.
  • The Controller updates the View, or selects a new View, based on the state of the Model and on the its own View navigation rules.
  • The Model provides data to the View, but knows nothing about how that data is presented. The Model also provides business services to the Controller, but knows nothing about user events the Controller might have received.
model view controller pattern
Model-View-Controller Pattern
  • Model = Persistent data
  • View =JSP
  • Servlet =Controller =FacesServlet
to create a jsf application you typically perform the following steps
To create a JSF application, you typically perform the following steps:
  • Define and implement the application Model classes
  • Describe the Model to the framework
  • Create application Views using JSP pages
  • Define data validation rules
  • Define View navigation for the Controller
defining the model
Defining the Model

public class DataBean {

protected String _string;

protected long _n_long;

protected double _n_real;

public DataBean() {

_string = "Default";

_n_long = 1000;

_n_real = 0.5;


public String getString() { return _string; }

public void setString(String string) {

_string = string; }

public long getLongnumber() { return _n_long;}

public void setLongnumber(long n_long) {

_n_long = n_long; }

public double getRealnumber() {

return _n_real; }

public void setRealnumber(double n_real) {

_n_real = n_real; }


describe the model to jsf
Describe the Model to JSF







create application views
Create Application Views

<%@ taglib uri="" prefix="f" %>

<%@ taglib uri="" prefix="h" %>



<title>Validating JSF Page</title>



<h1>Please enter the requested data</h1>



<b>Enter a string from three to twelve

characters in length:</b><br/>

<h:inputText id="string" required="true"

value="#{data.string}" size="20">

<f:validateLength minimum="3" maximum="12"/>


<h:message for="string" style="color: red;"/>






defining data validation
Defining Data Validation

When the user posts an input form to the Controller, the Controller validates each of the inputs

<h:inputText id="string" required="true"

value="#{data.string}" size="20">

<f:validateLength minimum="3" maximum="12"/>


<h:message for="string" style="color: red;"/>


This example shows how to perform server-side validation. JSF also provides a way to perform the requested validations on the client side. The default implementation of client-side validation runs as JavaScript in the Web browser.

defining view navigation for the controller
Defining View Navigation for the Controller

<h:commandButton id="submit"


value="Submit values"/>

In this case, the commandButton tells the Controller to execute the "validated" action if all inputs are valid.








This rule tells the Controller the following: if you receive valid inputs from a form in the page /jsp/values.jsp, and the action is 'validated', then go to page /jsp/valid.jsp.

why javaserver faces
Why JavaServer Faces
  • The promise of JSF is to bring rapid user-interface development to server-side Java.
  • JSF has these parts:
    • a set of pre-fabricated UI components
    • an event-driven programming model
    • A component model that enables third-party developers to supply additional components
a simple jsf applications
A Simple JSF Applications


<h:outputText value="#{msgs.pageTitle}"/>



<h:dataTable value="#{tableData.names}"



<h:outputText value="#{name.last}"/>




<h:outputText value="#{name.first}"/>





Code behind the page

web application analysis
Web Application Analysis
  • Web applications have two parts: the presentation layer and the business logic.
  • The presentation layer is concerned with the look of the application.
    • In “browser-speak”, the look is determined by the HTML tags that specify the layout, fonts, images and other elements to display the page.
web application analysis1
Web Application Analysis
  • The business logic is implemented in the Java code that determines the behavior of the application.
web application analysis2
Web Application Analysis
  • Some web application intermingle HTML and code.
  • The approach is easy to implement for simple applications in a single file.
  • For serious application development projects, mixing markup and code poses considerable problems.
behind the scenes
Behind the Scenes

Graphic ofHTML form




A JSF form is represented internally as a tree

UI components are managed on the server in a view, or component tree. The components can be wired directly to the values of JavaBean properties. Components are rendered to the client in HTML.

  • It is the responsibility of the person designing the UI to ensure that the user entered the correct type of information
  • In web design this was usually done when validation routines written in JavaScript
  • JSF handles validation in three ways:
    • At the UI component level
    • By validator methods in backing beans
    • By validator classes
process validations
Process Validations
  • In the Process Validation phase, JSF traverses the component tree and interrogates each component to make sure its submitted value is acceptable.
  • Validation is handled either directly by the component or delegated to one or more validators.
some jsf examples
Some JSF Examples
  • JSF Code Samples and Apps
servlet configuration
Servlet Configuration
  • JSF applications require a servlet, calledFacesServlet, which acts as a front controller for the entire application.
  • Servlets are configured in the web application’s deployment descriptor file, web.xml



<servlet-name>Faces Servlet</servlet-name>



using jsp includes
Using JSP includes
  • One of JSP’s key features is the ability to integrate content for multiple JSPs into a single page.

<jsp:include page =“disclaimer.jsp”/>


<jsp:include page =“footer.jsp”/>

issuing sql statements
Issuing SQL Statements
  • To issue SQL commands to a database, you need a connection object.
  • Using Java Naming and Directory Interface (JNDI)

String myUri = “java:cmp/env/jdbc/mydb”;

Context ctx = new InitialContext();

DataSource source (DataSource) ctx.lookup(myUri);

Connection conn = source.getConnection();

api documentation
API Documentation

jsf goals
JSF Goals
  • The core promise of JSF is support for UI components—reusable units of code.
  • JSF has a specific goal: to make web applications with less effort.
top ten reasons to prefer jsf to struts david geary s blog
Top Ten Reasons to Prefer JSF to Struts (David Geary’s Blog)
  • Components
  • Render Kits
  • Renderers
  • Value Binding Expressions
  • Event Model
  • Extensibility
  • Managed Beans (Dependency Injection)
  • POJO Action Methods
  • JSF is the standard Java-based web app framework
  • There's only one Struts
references cont d
References (cont’d)
  • The J2EE 1.4 Tutorial
  • Code Samples and Apps
  • Core Java ServerFacesDavid Geary, Cay Horstmann,Sun Microsystems Press Java Series