Java Server Faces Web Applications: Unit-V Internet Programming
Java Server Faces Web Applications: Unit-V Internet Programming
Web applications
UNIT- V
Internet Programming
JavaServer Faces (JSF)
• is a “server side user interface component framework for Java™ technology-based web
applications”
• is a specification and reference implementation for a web application development
framework
• Components
• Events
• Validators
• Back-end-data integration
• is designed to be leveraged by tools
• NetBeans, RAD (Rational Application Developer), Eclipse, JDeveloper, etc.
• is a Request-driven MVC
• uses component-based approach
• uses JSP for its display technology, but is not limited to it
Why JSF?
• MVC for web applications
• Easy to use
• Extensible Component and Rendering architecture
• Support for client device independence
• Standard
• Huge vendor and industry support
• Built-in UI component model (unlike JSP and Servlet)
• Offers finer-grained separation of behavior and presentation than JSP
• Component-specific event handling
• UI elements as stateful objects on the server
• UI-component and Web-tier concepts without limiting you to a particular scripting
technology or markup language
• Can work with any presentation technology including JSP
JSF Includes
• Set of APIs
• Two JSP custom tag libraries for expressing UI within JSP
• Server-side event model
• State management
• Managed beans
• Unified Expression Language
JSF is a UI Framework for Java Web
Applications
JSF Architecture
How the JSF Specification Fits In
(prior to Facelets)
JSF View
Components Rich UI-data-bound components Standard tags (JSTL) that are Struts-specific tag library
with events provided non-UI and very basic Only very basic, form-bean-bound
Custom components Custom components through tag components provided
libraries
Error handling and validation Validation framework None Validation framework driven by an
Many predefined validators XML file (validation.xml)
Scripting Scripts can be attached to events Embedded Java™ in the page Scripts written in Java Action
All components accessible from classes
scripts Form data but not components
accessible
Page flow Simple navigation file (faces- None Sophisticated, flexible framework
config.xml) XML file based
JARs required by
MyFaces
JSTL 1.2
• When Faces Servlet sees *.jsf it will look for *.jsp to create the view
• In hello.jsp all content that is JSF specific should be in enclosed in
<f:view> tag
• We also need to specify the needed JSP tag libraries
hello.jsp
• Here we do 3 things:
• Define "JSF core" and "JSF html" tag libraries
• JSP view (f:view tag)
• Use outputText component to show message
<?xml version="1.0" encoding="UTF-8" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
version="2.1">
...
<f:view>
<h:outputText
value="#{'Hello World! I am a h:outputText message'}" />
</f:view>
...
</jsp:root>
Application Configuration File
(faces-config.xml)
• faces-config.xml defines
• Page navigation rules
• Configures managed beans
• Other custom objects, such as custom components
• It is located in the WEB-INF folder of the project
• Basic structure:
<?xml version="1.0"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2">
...
</faces-config>
JSF Component Model
• A set of UIComponent classes for specifying the state and
behaviour of UI components
• A rendering model that defines how to render the components
in different ways
• One UI component may have several presentations
• Example: UICommand – button and hyperlink
• A server-side event-listener model that defines how to handle UI component
events
• A conversion model that defines how to plug in data converters onto a
component
• A validation model that defines how to register validators onto a component
JSF UI Components