JavaServer Faces: It is a server side component based user interface framework. It is used to develop web applications. It provides a well-defined programming.

Slides:



Advertisements
Similar presentations
JSF Portlet Backing Beans and UI Components Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in.
Advertisements

Apache Struts Technology
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Using JavaServer Pages Harry R. Erwin, PhD CIT304/CSE301.
Web applications using JavaServer Faces (JSF) A brief introduction 1JavaServer Faces (JSF)
Internet Technologies 1 Master of Information System Management Java Server Faces Model/View/Controller Design Pattern for Web Development Slides.
JavaServer Faces. Objectives To implement dynamic web pages with JavaServer Faces (JSF) technology To learn the syntactical elements of JavaServer Faces.
JavaServer Faces Dr Jim Briggs 1JavaServer Faces.
Java Server Faces Model/View/Controller Design Pattern for Web Development Slides adapted from “Core JavaServer Faces” by Geary and Horstmann and the J2EE.
Apache Struts Technology A MVC Framework for Java Web Applications.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Struts 2.0 an Overview ( )
UNIT-V The MVC architecture and Struts Framework.
JavaServer Faces: The Fundamentals Compiled from Sun TechDays workshops (JSF Basics, Web-Tier Codecamp: JavaServer Faces, Java Studio Creator; IBM RAD)
11. Java-Based Web: JSP, JSF. 2 Motto: Rule 1: Our client is always right Rule 2: If you think our client is wrong, see Rule 1. - Anonymous.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
JSP Standard Tag Library
1 Chính phủ điện tử TS. Phạm Văn Tính Khoa CNTT, ĐH Nông Lâm TP.HCM
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
MVC pattern and implementation in java
Pittsburgh Java User Group– Dec Java PureFaces: A JSF Framework Extension.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
CSCI 6962: Server-side Design and Programming Validation Tools in Java Server Faces.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
JavaServer Faces Jeff Schmitt October 5, Introduction to JSF Presents a standard framework for building presentation tiers for web applications.
ITCS 6010 SALT. Speech Application Language Tags (SALT) Speech interface markup language Extension of HTML and other markup languages Adds speech and.
Design Patterns Phil Smith 28 th November Design Patterns There are many ways to produce content via Servlets and JSPs Understanding the good, the.
CSE446 S OFTWARE Q UALITY M ANAGEMENT Spring 2014 Yazılım ve Uyguluma Geliştirme Yöneticisi Orhan Başar Evren.
JSF road map (NI) Clientside validation Show problems
CSCI 6962: Server-side Design and Programming Introduction to Java Server Faces.
Web applications using JavaServer Faces (JSF) A brief introduction 1JavaServer Faces (JSF)
CSCI 6962: Server-side Design and Programming Java Server Faces Components and Tags.
Session 1 SESSION 1 Working with Dreamweaver 8.0.
JSF Introduction Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
JSTL Lec Umair©2006, All rights reserved JSTL (ni) Acronym of  JavaServer Pages Standard Tag Library JSTL (like JSP) is a specification, not an.
Java Web Development with NetBeans IDE -- Kai Qian Chapter 5 JavaServer Faces (JSF) Technology.
JAVA SERVER FACES ADITI RAJORIYA UNI – ar2630. POINTS TO BE DISSCUSED WHAT IS JSF? WHY JSF? ARCHITECTURE JSF VERSIONS UI COMPONENTS JSF STRUCTURE AND.
JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
JSTL The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates core functionality common to many JSP applications.
Chính phủ điện tử TS. Phạm Văn Tính Khoa CNTT, ĐH Nông Lâm TP.HCM
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Spring MVC Essentials Getting started.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Preface IIntroduction Objectives I-2 Course Overview I-3 1Oracle Application Development Framework Objectives 1-2 J2EE Platform 1-3 Benefits of the J2EE.
JavaServer Faces framework Craig McClanahan is presented that created Struts web framework and based on experience gathered designed JavaServer.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Chapter 14 Using JavaBeans Components in JSP Documents.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
SDJ INFOSOFT PVT. LTD. 2 BROWSERBROWSER JSP JavaBean DB Req Res Application Layer Enterprise server/Data Sources.
Apache Struts Technology A MVC Framework for Java Web Applications.
Intro to JavaServer Faces Mimi Opkins CECS 493 Fall 2016.
Section 10.1 Define scripting
J2EE Platform Overview (Application Architecture)
The Expression Language Syntax
Event Handling Mimi Opkins CECS 493 Fall 2016.
JSP: Actions elements and JSTL
Play Framework: Introduction
Java Beans Sagun Dhakhwa.
Knowledge Byte In this section, you will learn about:
Unit 6-Chapter 2 Struts.
MSIS 655 Advanced Business Applications Programming
JavaServer Faces: The Fundamentals
Web Development Using ASP .NET
Enterprise Java Beans.
An Introduction to JavaScript
Presentation transcript:

JavaServer Faces: It is a server side component based user interface framework. It is used to develop web applications. It provides a well-defined programming model and consists of rich API and tag libraries. The latest version JSF 2 uses Facelets as its default templating system.It is written in Java. 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. The JSF Tag libraries are used to add components on the web pages and connect components with objects on the server. It also contains tag handlers that implements the component tag. With the help of these features and tools, you can easily and effortlessly create server-side user interface.

Benefits of JavaServer Faces 1) It provides clean and clear separation between behavior and presentation of web application. You can write business logic and user interface separately. 2) JavaServer Faces API?s 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. 3) 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.

ava Server Faces Versions History Jsf JSF 2.3 Expected in 2017 Release date Description Jsf JSF 2.3 Expected in 2017 It may includes major features: bean validation for complete classes, push communication using enhanced integration with cdi.  Jsf 2.2 21-05-2013 It has introduced new concepts like stateless views, page flow and the ability to create portable resource contracts. Jsf 2.1 22-11-2010 It was a maintenance release 2 of jsf 2.0. only a very minor number of specification changes. Jsf 2.0 01-07-2009 It was major release for ease of use, enhanced functionality, and performance. coincides with java ee 6. Jsf 1.2 11-05-2006 It has many improvements to core systems and apis. coincides with Java ee 5. initial adoption into java ee.  Jsf 1.1 27-05-2004 It was a bug-fix release. no specification changes. Jsf 1.0 11-03-2004 It was a initial specification released. 

Architecture of a JSF Application: A JSF application is made up of a collection of XHTML pages, Java classes, and JSF metadata. The XHTML pages make up the visual part of the web application, holding the various JSF tags , markup, and scripting content that define the UI elements. These Java classes include JavaBeans that hold various parts of the application data, together with Java classes that mediate the data by implementing various types from the JSF APIs, including event handlers, data validators, and data converters The JSF metadata defines how the XHTML pages and JavaBeans are treated in the JSF runtime. A mix of Java annotations and XML documents, this metadata defines the scope of the JavaBeans, how many instances are used, and their lifecycles, together with navigation rules, and can be used to control how the UI components are rendered.

Model-View-Controller: JSF technology is a framework for developing, building server-side User Interface Components and using them in a web application. JSF technology is based on the Model View Controller (MVC) architecture for separating logic from presentation. MVC helps to design an application well and how can we make our web application easy to maintain. The MVC design pattern splits an application design into three separate parts:  Model :       handles data and logic.  View :     handles output (presentation)  Controller: handles processing of an application.

We have created JSF project successfully We have created JSF project successfully. This project includes following files: index.xhtml: inside the Web Pages directory web.xml: inside the WEB-INF directory Whenever we run the project, it renders index.xhtml as output. Now, we will create an application which contains two web pages, one bean class and a configuration file. It requires the following steps in order to develop new application: Creating user interface Creating managed beans Configuring and managing FacesServlet

1) Create User Interface We will use default page index.xhtml to render input web page. Create a second web page which produce the output. Wihich is jsf page. After creating response.xhtml page. Now, 2) Create a Managed Bean It is a Java class which contains properties and getter setter methods. JSF uses it as a Model. So, you can use it to write your business logic also. 3) Configure Application To configure application, project contains a web.xml file which helps to set FacesServlet instances. You can also set your application welcome page and any more.

JavaServer Faces Tags: The collection of JavaServer Faces tags falls into a number of categories: those for UI components, those for control flow and string manipulation within a page, those to create UI components from other tags, “pass-through” tags and attributes that allow nonstandard markup to be used in a JSF page, and finally the core set of JSF tags that bind everything together. 1.UI components: JavaServer Faces provides rich set of components library to define the architecture of application. 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.

JSF Managed Bean: It is a pure Java class which contains set of properties and set of getter, setter methods. 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 It also works as model for JFS Framework.

JSF Managed Bean Example: public class User {   private String name;   public String getName() {   return name;   }   public void setName(String name) {   this.name = name;   }    }  You can use this bean by the following ways. By configuring into XML file. By using annotations.

Configuring Managed Bean into XML file: <managed-bean> <managed-bean-name>user</managed-bean-name> <managed-bean-class>User</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> Configuring Managed Bean using Annotations: import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; @ManagedBean // Using ManagedBean annotation @RequestScoped // Using Scope annotation public class User { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } }

The @ManagedBean annotation in a class automatically registers that class as a resource with the JavaServer Faces. Such a registered managed bean does not need managed-bean configuration entries in the application configuration resource file. This is an alternative to the application configuration resource file approach and reduce the task of configuring managed beans. The @RequestScoped annotation is used to provide scope for ManagedBean. You can use annotations to define the scope in which the bean will be stored. You can use following scopes for a bean class: Application (@ApplicationScoped): Application scope persists across all users? interactions with a web application. Session (@SessionScoped): Session scope persists across multiple HTTP requests in a web application. View (@ViewScoped): View scope persists during a user ?s interaction with a single page (view) of a web application. Request (@RequestScoped): Request scope persists during a single HTTP request in a web application. None (@NoneScoped): Indicates a scope is not defined for the application. Custom (@CustomScoped): A user-defined, nonstandard scope. Its value must be configured as a java.util.Map. Custom scopes are used infrequently.

f: Core Tags: The JavaServer Faces core tag library contains the basic tags that most JavaServer Faces pages will use. The core tags are contained in the namespace xmlns:f=http://xmlns.jcp.org/jsf/core Most of the tags fall into the three important categories of tags that validate data,in other words, check that the values of data used in a tag fall within certain conditions, tags that manageevents generated in the JavaServer Faces page,and tags that deal with converting data at the page level into a suitable form for consumption by the JavaBeans that back the page.

Data Validation: JavaServer Faces provides various levels of validation that you can usethis purpose.Often, it is enough to use the built-in tags for validation, which is the simplest approach and covers the most frequent types of validation. The validator is applied to a tag that takes input by making it a subelement of the tag whose value needs to be checked Tag Function <f:validateLength> Checks the minimum and/or maximum length of an inputstring <f:validateDoubleRange> Checks the minimum and/or maximum value of a input double <f:validateLongRange> Checks the minimum and/or maximum value of a input long <f:validateRequired> Requires some nonempty value to be inpute tag whose value needs to be checked.

EXAMPLE: <h:form> <h:inputText id="username_component" validatorMessage="Username must be between 4 and 10 characters"> <f:validateLength minimum="4" maximum="10"/> </h:inputText> </h:form> Input values may also be validated with the Bean Validation API or with regular expressions. Tag Function <f:validateBean> Checks a value against an implementation of the Beans Binding API javax.faces.validator.BeanValidator. <f:validateRegex> Checks a value against a regular expression. Either in the form of a regex expression string: <f:validateRegex pattern="/[0-9a-zA-Z]"/> or as an implementation of the javax.faces.validator. RegexValidator class: <f:validateRegex binding="myRegexValidator">

You can also implement your own validator You can also implement your own validator. @FacesValidator("myValidator") public class MyValidator implements Validator { public void validate(FacesContext context,UIComponent component, Object value) throws ValidatorException { // check value // throw ValidatorException if it does not pass the check }

event handling tags: event handling tags can be used to register either an instance or a class that implements a certain JavaServer Faces defined event listener interface class. When the tag is used as a subelement of the appropriate user interface component, the event listener they specify is added to that user interface component. When the user interface component’s state changes, the page data is submitted to the Java EE web container, the corresponding event listener is called, and the page regenerated and transmitted back to the browser.

Tag Function <f:actionListener> For use with command buttons and links, this tag registers the given implementation of javax .faces.event.ActionListener which is then notified when the component’s state changes. <f:actionListener type ="actionlistener impl classname"> <f:actionListener binding = "expression evaluating to actionlistener instance">

<f:valueChangeListener> For use with all input components and lists, this tag registers the given implementation of javax .faces.event.ValueChangeListener, which is then notified when the component’s state changes. <f:valueChangeListener type = "valuechangelistener impl classname"> <f:actionListener binding = "expression evaluating to valuechangelistener instance"> <f:setPropertyActionListener> For use with command buttons and links, this tag lets you directly set the value of a property on a managed bean. <f:setPropertyActionListener target="#{myBean.babyName}" value="#{nameList.currentName}" />

Data Converters: JavaServer Faces allows for a number of different kinds of conversions that can cater to several different data types and conversion needs. The starting point for these conversions is the conversion tags in the JavaServer Faces core library. Tag Function <f:convertNumber> Converts a Double or Long object to and from a variety of formats, including standard currency formats, and number formats, specifying ranges for the number of integer and fractional part digits, as well as grouping patterns. <f:convertDateTime> Converts a Date object to and from a variety of humanreadable date formats suitable for a variety of locales and time zones, and in a variety of date formats.

JSTL Core Tags We have encountered the Standard Tag Library already. The control flow tags are also available in JavaServer Faces. Here is a summary of these tags and their function. Tag Purpose <c:catch> Catches any throwable thrown within this tag, using the name of the var attribute to hold the throwable. <c:choose> Defines a set of mutually exclusive choices, used in conjunction with the <c:when> and <c:otherwise> tags, like a Java switch statement. <c:if> Simple conditional tag, based on the condition supplied in the test attribute evaluating to true. <c:forEach> Tag for iterating over collections. <c:otherwise> Tag for the default case in a <c:choose> tag. <c:set> Tag to set a page variable by name. <c:when> Simple conditional tag, for use in <c:choose> tags, for example.

Extensibility and Modularity: JavaServer Faces includes many ways to extend its base functionality and to modularize pieces of JavaServer Faces code to promote reuse within an application and across applications. Developers can create custom UI components in two main ways. First, to render a new user interface component on the page, they can provide a new subclass of UIComponent and associate it with a new tag and a new set of control attributes. In this way, many developers have created libraries of new HTML components and custom text components, for example, image components that include mapping functionality.

Second, snippets of JavaServer Faces markup may be packaged into an XHTML file as a composite component and associated with a tag using a tag library descriptor. In this way, commonly occurring groupings of tags in JavaServer Faces pages, such as OK cancel button panels and image display panels, can be bundled into a single tag, thereby making it easier to reuse such commonly recurring elements in an application. JavaServer Faces offers a couple of techniques to help web applications that have predefined user interaction pathways. A wizard that collects registration data or a sequence of web forms that help you make and pay for an online purchase are good examples of such interaction pathways. JavaServer Faces defines Faces Flows. This consists of a managed bean scope

with the ability to define a set of flows between JavaServer Faces pages and the ability to easily share context, such as a shopping basket or custom registration, between the pages and inject logic into the transitions.