0% found this document useful (0 votes)
8 views17 pages

VND - Openxmlformats Officedocument - Presentationml.presentation&rendition 1

Uploaded by

dakshpatidar245
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views17 pages

VND - Openxmlformats Officedocument - Presentationml.presentation&rendition 1

Uploaded by

dakshpatidar245
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Java Server Faces

Satish Bansal
Java Server Faces
• It is a server side component based user
interface framework. It is used to develop web
applications.
• The JSF API provides components (inputText,
commandButton etc) and helps to manage their
states. It also provides server-side validation,
data conversion, defining page navigation,
provides extensibility, supports for
internationalization, accessibility etc.
Benefits of JavaServer Faces

>It provides clean and clear separation between behavior and


presentation of web application. You can write business logic and user
interface separately.
>JavaServer Faces APIs are layered directly on top of the Servlet API.
Which enables several various application use cases, such as using
different presentation technologies, creating your own custom
components directly from the component classes.
>Including of Facelets technology in JavaServer Faces 2.0, provides
massive advantages to it. Facelets is now the preferred presentation
technology for building JavaServer Faces based web applications.
Facelets
• It is a light weight page declaration language which is used to build JavaServer Faces views
using HTML style. It includes the following features:
• It uses XHTML for creating web pages.
• It supports Facelets tag libraries in addition to JavaServer Faces and JSTL tag libraries.
• It supports the Expression Language (EL).
• It uses templating for components and pages.
• Advatages
• It supports code reusabilty through templating and composite components.
• It provides functional extensibility of components and other server-side objects through
customization.
• Faster compilation time.
• It validates expression language at compile-time.
• High-performance rendering.
• JavaServer Faces technology supports various tag libraries to add components to a web page. To
support the JavaServer Faces tag library mechanism, Facelets uses XML namespace declarations.
Facelets
• The following table shows tag libraries supported by
Facelets.

Tag Library URI Prefix Example Contents


JavaServer Faces http:// ui: ui:component Tags for templating
Facelets Tag Library xmlns.jcp.org/jsf/ ui:insert
facelets
JavaServer Faces HTML h: h:head h:body JavaServer Faces
Tag Library http:// h:outputText component tags for
xmlns.jcp.org/jsf/ h:inputText all UIComponent
html objects
JavaServer Faces http:// f: f:actionListener Tags for JavaServer
Core Tag Library xmlns.jcp.org/jsf/ f:attribute Faces custom
core actions that are
independent of any
particular render kit
JSF Features
• Component Based Framework
• Implements Facelets Technology
• Integration with Expression Language
• Support HTML5
• Ease and Rapid web Development.
• Support Internationalization
• Bean Annotations
• Default Exception Handling
• Templating
• Inbuilt AJAX Support
• Security
JSF Architecture
JavaServer Faces Lifecycle
The lifecycle can be divided into two main
phases: Execute and Render.
A JavaServer Faces page is represented by a
tree of components, called a view.
The JavaServer Faces implementation
performs all these tasks as a series of six steps
in the JavaServer Faces request-response
lifecycle.
•Restore view phase
•Apply request values phase; process
events
•Process validations phase; process
events
•Update model values phase; process
events
•Invoke application phase; process events
•Render response phase
JSF Managed Bean
• It is a pure Java class which contains set of properties and set of getter,
setter methods.
• Managed Beans is a Java bean managed by JSF framework. Managed
bean contains the getter and setter methods, business logic.
• Following are the common functions that managed bean methods
perform:
• Validating a component's data
• Handling an event fired by a component
• Performing processing to determine the next page to which the
application must navigate
• Managed beans works as Model for UI component. Managed Bean
can be accessed from JSF page.
JSF User Interface Component Model
• It includes the following:
• Rich set of classes for specifying the state and behavior
of user interface components.
• A rendering model that defines how to render the
components in various ways.
• A conversion model that defines how to register data
converters onto a component.
• An event and listener model that defines how to handle
component events.
• A validation model that defines how to register
validators onto a component.
The following table contains the user interface
components.
Tag Functions Rendered As Appearance
h:inputText It allows a user to input a string. An HTML <input type="text"> A field
element
h:outputTex It displays a line of text. Plain text Plain text
t
h:form It represents an input form. An HTML <form> element
h:command It submits a form to the An HTML <input type=value> A button
Button application. element for which the type value can
be "submit", "reset", or "image"
h:inputSecr It allows a user to input a string An HTML <input type="password"> A field that displays
et without the actual string element a row of characters
appearing in the field. instead of the actual
string entered.
h:inputTexta It allows a user to enter a An HTML <textarea> element A multirow field
rea multiline string.
The following table contains the user interface components.

Tag Functions Rendered As Appearance


h:commandLin It links to another page or An HTML <a href> element A link
k location on a page.
h:inputHidden It allows a page author to include An HTML <input
a hidden variable in a page. type="hidden"> element
h:inputFile It allows a user to upload a file. An HTML <input A field with a Browse
type="file"> element button
h:graphicImage It displays an image. An HTML <img> element An image
h:dataTable It represents a data wrapper.
An HTML <table> element A table that can be
updated dynamically.
h:outputLink It links to another page or An HTML <a> element A link
location on a page without
generating an action event.
JSF Validation
• JavaServer Faces technology provides a set of standard classes
and associated tags that you can use to validate elements data.
alidator class Tag Function
BeanValidator validateBean It is used to registers a bean validator for the component.
DoubleRangeVa validateDouble It is used to check whether the local value of a component is within a
lidator Range certain range or not. The value must be floating-point or convertible to
floating-point.
LengthValidator validateLength It is used to check whether the length of a component's local value is
within a certain range or not. The value must be a java.lang.String.
LongRangeVali validateLongR It is used to check whether the local value of a component is within a
dator ange certain range or not. The value must be any numeric type or String that
can be converted to a long.
RegexValidator validateRegex It is used to check whether the local value of a component is a match
against a regular expression from the java.util.regex package or not.
RequiredValidat validateRequir It is used to ensure that the local value is not empty on an
or ed EditableValueHolder component.
JSF Bean Validation
• JSF provides validation constraints for bean model in the form of
annotations. You can place that annotations on a field, method,
or class of a JavaBeans component, such as a managed bean.
• JSF also provides facility to create custom or user defined
constraints. The built-in constraints are available in the
javax.validation.constraints package and tabled in the following
table.
Constraint Description Example
@NotNull It is used to set not null constraint to the value of the field or property. @NotNull String username;
@Null It is used set null constraint to the value of the field or property. @Null String unusedString;
@Size It is used to specify size of field or property. The size of the field or @Size(min=2, max=240)
property is evaluated and must match the specified boundaries. Use one of String briefMe
the optional max or min elements to specify the boundaries.
@Digits It is used to set constraint that the value of the field or property must be a @Digits(integer=6,
number within a specified range. The integer element specifies the fraction=2) BigDecimal price;
maximum integral digits for the number, and the fraction element
specifies the maximum fractional digits for the number.
JSF and JDBC

You might also like