Professional Documents
Culture Documents
Kedar Hukeri
Understand faces-config.xml
Continued…
Course Agenda
1. Steps in the development process
2. UI component model
3. Navigation model
4. Bean management
3. Localization
6. Lab exercise
Tea Break :- )
Introduction to JSF
What is JSF - A server side user interface
component framework for Java technology-based
web applications
Components
Events
Components
Events
Validators
Back-end-data integration
including JSP
Why JSF?...
JSP and Servlet
No built-in UI component model
Struts
No built-in UI component model
components
No built-in support of multiple renders (struts
Server
request
Client
Response
JSF Design Goals
Request Controller
FacesServl
Browser et Model
View
Response JSP UI
JSF Architecture
– http://java.sun.com/j2ee/javaserverfaces/download.html
JSF Page
Desktop
Browser HTML
RenderKit
App
Front ctrl
Backend
WML
RenderKit
Phone
Important Basic
Capabilities
Extensible UI component model
Flexible rendering model
Event handling model
Validation framework
Basic page navigation support
Internationalization
Accessibility
Key JSF Concepts…
UIComponents
Render-independent characteristics
components
May support more then one component type
specification
Relationship to Other JSRs
JSF is based on:
Servlet 2.3 (JSR-53)
Portals (JSR-168)
JSF Developer Roles
Tools
Page Author Developer
Component
Developer
JSF
Application Implementor
Developer
Roles Definition…
Page Author – Creates the user interface of a web
application
Familiar with markup language(s) to be used
JavaBean APIs
Roles Definition
Tool Provider – creates tools to assist page
authors, component writers, and application
developers
GUI- oriented page development tools
description)
Roles Definition
Tool Provider-
Web application frameworks that utilize JSF
components for their user interface
JBuilder, Eclipse, WSAD
Conversion
Request Processing
Lifecycle
Request Processing
Life-cycle handles two types of requests
Initial request & postback
Initial request
A user requests the page for the first time
helloForm
FacesContext
Phase 3 – Process
Validation Phase
JSF implementation processes all validations
registered on the components in the tree
In case of validation errors
Error messages are queued in FacesContext
Response phase
Example
userNo has to be between 1 and 10
Phase 4 – Update Model
Values Phase
JSF implementation walks the component tree
and set the corresponding server side object
properties to the components’ local values
Updated the bean properties pointed at by an
property type
Example in gretting.jsp
userNumber property of the UserNumberBean
tree
If errors in previous phases, original page is
UI Component Model
What is a UI Component?
UI Component Classes
Driving event-handling
a button or a hyperlink
Built-in UI Component
Classes…
UICommand
Represents a control that fires actions when
activated
UIForm
Encapsulates a group of controls that submit
Is a subclasses of UIOutput
UIOutput
Displays data output on a page
UIPanel
Display a table
UIParameter
Represents substitution parameters
Built-in UI Component
Classes…
UISelectItem
Represents a single item in a set of items
UISelectItems
Represents an entire set of items
UISelectBoolean
Allows a user to set a boolean value on a
<h:command_link>
RenderKit
Defines how component classes map to
component tags appropriate for a particular
client
JSF implementation includes a built-in RenderKit
for rendering to an HTML client
For every UI component that a RenderKit
supports, the RenderKit defines a set of Renderer
objects
Renderer Object
Defines a different way to render the particular
component to the output defined by the
RenderKit
Example
UISelectOne component has three different
renderers
One of them render the component as a set
of radio buttons
Another renders the component as a combo
box
The third one renders the component as a
list box
Introduction to JavaServer
Faces
UIComponent class
Rendering attributes, defined by the Renderer
Example Tags
<command_button> & <command_link> tags
“command” defines UI component
attribute
Greeting.jsp
<f:view>
<h:form id="helloForm" >
<h2>Hi. My name is Duke. I'm thinking
of a number from
<h:output_text
value="#{UserNumberBean.minimum}
"/> to
<h:output_text
value="#{UserNumberBean.maximum}
"/>. Can you guess it?
</h2>
<h:graphic_image id="waveImg"
Introduction to JavaServer
Faces
Conversion Model
Presentation view
Validation Model
Application Configuration
render kits
Usually names as faces-config.xml
A <faces-config> tag must enclose all of the
other declarations
<faces-config>
…
</faces-config>
Faces-config.xml of
guessNumber…
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD
JavaServer Faces Config 1.0//EN"
"http://java.sun.com/dtd/web-
facesconfig_1_0.dtd">
<faces-config>
<application>
<locale-config>
Faces-config.xml of
guessNumber
<navigation-rule>
...
<from-view-id>/greeting.jsp</from-view-
id>
...
</navigation-rule>
<navigation-rule>
...
<from-view-id>/response.jsp</from-view-
id>
Application Configuration
File
You can have more than one application
configuration file
There are three ways that you can make these
files available to the application
A resource named /META-INF/faces-config.xml
javax.faces.application
A resource named faces-config.xml in the
prefix=“h” %>
<%@ taglib uri=http://java.sun.com/jsf/core/
prefix=“f” %>
<f:view> element
Represents UIViewRoot component
All component tags on the page must be enclosed
in the view tag
<f:view>
…other faces tags, possibly mixed with other
content…
</f:view>
Optional locale attribute
Overrides the Locale stored in the UIViewRoot
Nested View’s
Use <f:subview> element in order to include a JSF
page inside another JSP page
<f:subview>
jsp:include page=“theNestedPage.jsp”
<f:subview>
Introduction to JavaServer
Pages
component
<f:valuechange_listener>
Registers a value-change listener on a parent
component
JSF Advantages
Custom GUI controls
– JSF provides a set of APIs and associated custom tags to
create
HTML forms that have complex interfaces
Event handling
– JSF makes it easy to designate Java code that is invoked
when forms
are submitted. The code can respond to particular buttons,
changes
in particular values, certain user selections, and so on.
Managed beans
– In JSP, you can use property="*" with jsp:setProperty to
automatically populate a bean based on request
parameters. JSF
extends this capability and adds in several utilities, all of
which
serve to greatly simplify request param processing.
JSF Advantages…
Continued 2
Form field conversion and validation
– JSF has built-in capabilities for checking that form values
are in the
required format and for converting from strings to various
other data
types. If values are missing or in an improper format, the
form can
be automatically redisplayed with error messages and with
the
previously entered values maintained.
Centralized file-based configuration
– Rather then hard-coding information into Java programs,
many JSF
values are represented in XML or property files. This loose
coupling
means that many changes can be made without modifying
or
JSF Advantages…
Continued 3
Custom components
– JSF makes it relatively easy to combine complex GUIs
into a single manageable component; Struts does not
Support for other display technologies
– JSF is not limited to HTML and HTTP; Struts is
Access to beans by name
– JSF lets you assign names to beans, then you refer to
them by name in the forms. Struts has a complex process
with several levels of indirection where you have to
remember which form is the input for which action.
Expression language
– The JSF expression language is more concise and
powerful than the Struts bean:write tag.
This is less advantageous if using JSP 2.0 anyhow.
JSF Advantages…
Continued 4
Simpler controller and bean definitions
– JSF does not require your controller and bean classes to
extend any particular parent class (e.g., Action) or use
any particular method (e.g., execute). Struts does.
Simpler config file and overall structure
– The faces-config.xml file is much easier to use than is the
struts-config.xml file. In general, JSF is simpler.
More powerful potential tool support
– The orientation around GUI controls and their handlers
opens possibility of simple to use, drag-and-drop IDEs
Installing and Configuring JSF:
Sun Reference Implementation
– http://java.sun.com/j2ee/javaserverfaces/download.html
API Javadocs
– http://java.sun.com/j2ee/javaserverfaces/1.1/docs/api/
• Same as the MyFaces version
• Tag library docs
– http://java.sun.com/j2ee/javaserverfaces/1.1/docs/tlddocs/
• Much better than the MyFaces version
• faces-config.xml annotated DTD
– http://horstmann.com/corejsf/faces-config.html
• MyFaces References
– http://wiki.apache.org/myfaces/
• User's Guide, extensions documentation, FAQs, etc.
Summary
JSF provides many useful features for
Developing complex GUIs & handling events
THANKS!!!