Introduction to Java Server Faces (covered topics) ● Reasons to use „Java Server Faces“ ● JSF application structure ● JSF component model ● JSF managed.

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
The Web Warrior Guide to Web Design Technologies
JBoss Seam: Contextual Components Jason Bechtel
Object-Oriented Enterprise Application Development Tomcat 3.2 Configuration Last Updated: 03/30/2001.
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.
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.
Session-01. Layers Struts 2 Framework The struts 2 framework is used to develop MVC-based web application. Struts 1.0 was released in June The.
Introduction to JavaServer Faces Jeff Swisher Director of Consulting Services Dunn Solutions Group.
ECE356 – Database Systems Lab 1 – Building a Web Project with NetBeans Tiuley Alguindigue Lab Instructor – University of Waterloo, E & CE Dept. Fall 2013.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Stateful Web Application Development with Spring Web Flow John Case Senior Consultant Centare Group, Ltd.
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.
Java Server Faces Çağatay Çivici Apache MyFaces Team Member
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
Pittsburgh Java User Group– Dec Java PureFaces: A JSF Framework Extension.
Java Beans.
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.
1 Introduction to JavaServerFaces & MyFaces Anudeep Jassal.
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.
JDeveloper 10g and JavaServer Faces: High-Performance UIs on the Web Avrom Roy-Faderman Senior Programmer May, 2006.
JavaServer Faces Jeff Schmitt October 5, Introduction to JSF Presents a standard framework for building presentation tiers for web applications.
CSE446 S OFTWARE Q UALITY M ANAGEMENT Spring 2014 Yazılım ve Uyguluma Geliştirme Yöneticisi Orhan Başar Evren.
1 Lecture 24 George Koutsogiannakis Spring 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
CSCI 6962: Server-side Design and Programming Introduction to Java Server Faces.
Mark Dixon 1 12 – Java Beans. Mark Dixon 2 Session Aims & Objectives Aims –To cover the use of Java Beans Objectives, by end of this week’s sessions,
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–
Fall CIS 764 Database Systems Design L8. Web ….
Project Overview Graduate Selection Process Project Goal Automate the Selection Process.
Java Web Development with NetBeans IDE -- Kai Qian Chapter 5 JavaServer Faces (JSF) Technology.
JavaServer Faces: Sample App + Life Cycle Compiled from Sun TechDays workshops (JSF Basics, Web-Tier Codecamp: JavaServer Faces, Java Studio Creator)
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)
Chính phủ điện tử TS. Phạm Văn Tính Khoa CNTT, ĐH Nông Lâm TP.HCM
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 41 JavaServer Face.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Spring MVC Essentials Getting started.
© 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.
13 Copyright © 2004, Oracle. All rights reserved. Adding Validation and Error Handling.
Chapter 12© copyright Janson Industries Java Server Faces ▮ Explain the JSF framework ▮ SDO (service data objects) ▮ Facelets ▮ Pagecode classes.
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.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
Chapter 2 Java Struct 2. Content Basic MVC Architecture Struts 2 Overview Struts 2 - Architecture.
12 Copyright © 2004, Oracle. All rights reserved. Using ADF Struts 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.
CS520 Web Programming Spring – Web MVC Chengyu Sun California State University, Los Angeles.
Intro to JavaServer Faces Mimi Opkins CECS 493 Fall 2016.
Introduction to JavaServer Faces and the Woodstock UI Components Presenter Name
Examples with Java Server Faces (covered topics)
The Expression Language Syntax
Event Handling Mimi Opkins CECS 493 Fall 2016.
JSP (Java Server Page) JSP is server side technology which is used to create dynamic web pages just like Servlet technology. This is mainly used for implementing.
J2EE Lecture 4: Advanced Concepts in JSF
Unit 6-Chapter 2 Struts.
JSF Portlet Navigation and Event Listeners
Introduction to Struts
Java Web Application Framework
JavaServer Faces: The Fundamentals
Presentation transcript:

Introduction to Java Server Faces (covered topics) ● Reasons to use „Java Server Faces“ ● JSF application structure ● JSF component model ● JSF managed beans model ● JSF navigation model ● JSF error validation model ● JSF versions (1.0, 1.1, 1.2, 2.0) ● JSF implementations

Some reasons to use JSF ● JSF is standard for Java web framework. ● JSF is MVC model 2 based framework => separation between UI, business logic and data. ● JSF is component oriented and event driven framework. ● Choice between many JSF implementations, both free and commercial. ● JSF vendors provide rich set third party UI components, both free and commercial. ● IDE support (Eclispe, NetBeans, JBuilder,...).

Common WAR structure CommonWebApplication.war index.jsp another.jsp WEB-INF web.xml lib somelibrary.jar anotherlibrary.jar classes package structure SomeClass.class AnotherClass.class

JSF enabled WAR structure (1 of 2) WebApplicationWithJSF.war index.jsp another.jsp WEB-INF web.xml (with changes) faces-config.xml lib jsflibrary.jar anotherlibrary.jar classes package structure SomeClass.class AnotherClass.class

JSF enabled WAR structure (2 of 2) ● web.xml – includes JSF specific configuration (JSF servlet mappings, additional configuration files, specific JSF parameters,...). ● faces-config.xml – this is the default JSF configuration file. It includes navigation rules, configuration of backing beans, converters, validators... ● jsflibrary.jar – one or more JAR files which represents the JSF implementation.

Quick overview of JSF components (1 of 2) ● JSF components are custom tags. ● JSF standard defines two types of JSF component tags: html tags and core tags. ● HTML tags represent html components like text fields, buttons, form,... There are 25 standard html tags. ● Core tags allows you to take advantages of features of JSF framework, like validation, conversion, event handling,... There are 18 standard core tags.

Quick overview of JSF components (2 of 2) ● JSF input components can be restricted with validators and type converters. ● JSF command components can raise events on the server (JSF is event driven framework). ● JSF components use custom implementation of EL (expression language) to access data in managed beans.

JSF components (examples 1 of 3) JSF tag in JSP page: Rendered HTML response may be like this:

JSF components (examples 2 of 3) JSF tag in JSP page: Rendered HTML response may be like this:

JSF components (examples 3 of 3)...HTML tags...JSF component tags...HTML tags Content of JSF enabled JSP page:

JSF Life Cycle (propaganda) ● JSF life cycle (multiple phases) is conceptually different from JSP life cycle (single phase with direct evaluation). ● JSF life cycle phases are not compatible with JSP life cycle => JSP and JSF technologies experience difficulties with shared resources (accessing one and the same data via EL for example) => software developers experience severe difficulties too.

JSF Life Cycle Phases (1 of 7) Phase 1: Restore view phase Phase 2: Apply request values phase Phase 3: Process validations phase Phase 4: Update model values phase Phase 5: Invoke application phase Phase 6: Render response phase

JSF Life Cycle Phases (2 of 7) Phase 1: Restore view ● Invoked by clicking a link, button, etc. ● View is created or restored (in case of POST request) and then saved in FacesContext. ● Binding of components to event handlers and validators. ● Component tree is generated or rebuilt (in case of POST request).

JSF Life Cycle Phases (3 of 7) Phase 2: Apply request values ● Components retrieve their new values and store them locally. ● Component values are converted. ● Error messages are queued in FacesContext. ● Immediate – conversion, validation, bean updates and events are processed in this phase.

JSF Life Cycle Phases (4 of 7) Phase 3: Process validations ● Local component values are validated using the validation rules registered for the component. ● Validation error messages and conversion error messages are added to FacesContext. ● If validation fails – proceed to Render response phase.

JSF Life Cycle Phases (5 of 7) Phase 4: Update model values ● Local component values are set to the corresponding managed bean properties. ● If local component value type is incompatible with managed bean property type – proceed to Render response phase.

JSF Life Cycle Phases (6 of 7) Phase 5: Invoke application ● Server side events are invoked. ● Application level events are applied (for example navigation rules).

JSF Life Cycle Phases (7 of 7) Phase 6: Render response ● On initial request components are added to the component tree. ● Content view state is saved after the response.

JSF Life Cycle Phases (overview 1 of 2) ● Restore view - creates new page or restores the previous page. ● Apply request values - set component submitted values to request values. ● Process validations - Validate component values. Set component values to submitted values if valid.

JSF Life Cycle Phases (overview 2 of 2) ● Update model values - set backing bean values to component values. ● Invoke application - execute actionListeners and actions. ● Render response - return response and save the view state.

How the „immediate“ atribute works ● JSF input and command components have special attribute, called immediate. ● If immediate attribute is set to „true“– validation, conversion and events are processed in Apply request values phase.

Why is this attribute so special? ● Immediate attribute allows to navigate from one page to another while ignoring validation. ● We can make one or more components „high priority“ for validation. This can reduce number of error messages shown.

Immediate attribute examples (1 of 2) <h:inputText id=”someId” value=”edit me” immediate=“true“ required=“true“ /> JSF tag in JSP page: Result: ● This component will be validated in Apply request values phase. ● If the value is empty – error message will appear. Other non-immediate component error messages are ignored.

Immediate attribute examples (2 of 2) <h:commandButton id=”someId” value=”Click to go back” action=“goBack“ immediate=“true“ /> JSF tag in JSP page: Result: ● The action method is invoked in Apply request values phase. ● The action method is invoked before any non- imediate value validation and before any managed bean updates.

JSF Managed Beans ● Managed beans (for non-command components) are Java classes. ● Managed beans represent the Model part of MVC in JSF (for non-command components). ● Managed beans can have „Controller“ functionality (for command components). ● Managed beans are described and configured in faces-config.xml. ● Managed beans can have different scopes (request, session, aplication).

Simple managed bean example (1 of 3) package sample; public class MyBean { private String myName; public MyBean() { myName = “Ivan Davidov“; } public void setMyName(String newName) { myName = newName; } public String getMyName() { return myName; } } Managed bean class MyBean.java:

Simple managed bean example (2 of 3) myBean sample.MyBean session XML snippet in faces-config.xml:

Simple managed bean example (3 of 3)...HTML tags...HTML tags How to use in JSF components:

JSF Navigation Model ● Navigation model defines rules that allow you to define navigation from view to view. ● Navigations are defined in faces-config.xml.

Simple navigation example (1 of 3) /signin/login.jsp correctLogin /signin/success.jsp incorrectLogin /signin/wrongpass.jsp faces-config.xml snippet for navigation:

Simple navigation example (2 of 3) login.jsp...HTML tags...HTML tags

Simple navigation example (3 of 3) SigninBean.java package sample; public class SigninBean { // Standard Java bean properties goes here public String loginMethod() { if (getUser().equals(“ivan“) && getPass().equals(“12345“)) { // login is correct return “correctLogin“; } // login is incorrect return “incorrectLogin“; } }

JSF Error Validation Model There are four forms of validation within JSF: ● Built-in validation components. ● Application level validation. ● Custom validation components. ● Validation methods in backing beans.

Built-in validation components Core tag validators have common signature: Examples: ●

Simple validation example...HTML tags...JSF tags...More JSF tags...HTML tags register.jsp

Application level validation Implemented as backend code inside the action method of a managed bean. Advantages and disadvantages: ● Easy to implement. ● No nead for separate class (custom validator). ● Occurs after all other forms of validation. ● Difficult to manage in large applications.

Application level validation (example) Part of MyBean.java public String loginMethod() { FacesContext ctx = FacesContext.getCurrentInstance(); if (getUser() == null || getUser().equals(““) { // user field is empty FacesMessage message = new FacesMessage(); message.setSeverity(FacesMessage.SEVERITY_ERROR); message.setSummary(“User field is empty.“); // add error message to context ctx.addMessage(“regForm:ageId“, message); return ““; }...other backend application logic (don't forget to return String at the end). }

Validation methods in managed beans ● Implemented as method in managed bean with the following signature: public void methodName(FacesContext context, UIComponent component, Object value);

Validation method (example 1 of 2) Part of MyBean.java public void validateUser(FacesContext context, UIComponent component, Object value) { String userName = (String) value; if (userName == null || userName.equals(““)) { // validation fails for this component. ((UIInput)component).setValid(false); FacesMessage message = new FacesMessage(“User field is empty“); context.addMessage(component.getClientId(context), message); } }

Validation method (example 1 of 2)...HTML tags...JSF tags...More JSF tags...HTML tags register.jsp

JSF Versions ● JSF 1.0 – the first JSF standard. ● JSF 1.1 – bugfix release, no changes. ● JSF 1.2 – added new features (unified EL, better error messages support, etc.). ● JSF 2.0 – future release, expected in Expected better error handling model, skin support, etc.

JSF Implementations ● Sun Reference Implementation (Sun RI). ● Apache MyFaces.

Additional resources ● JSF tutorials: ● JSF introduction step by step: