JavaServer Faces Jeff Schmitt October 5, 2006. Introduction to JSF Presents a standard framework for building presentation tiers for web applications.

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

Web Development with Karsten Schulz Terp-Nielsen Master Principal Sales Consultant Oracle Denmark.
Apache Struts Technology
© Yaron Kanza Advanced Java Server Pages Written by Dr. Yaron Kanza, Edited by permission from author by Liron Blecher.
Expression Language Lec Umair Javed©2006 Generating Dynamic Contents Technologies available  Servlets  JSP  JavaBeans  Custom Tags  Expression.
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Web applications using JavaServer Faces (JSF) A brief introduction 1JavaServer Faces (JSF)
JBoss Seam: Contextual Components Jason Bechtel
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.
Struts Basics SSE USTC Qing Ding. Agenda What is and Why Struts? Struts architecture – Controller: Focus of this presentation – Model – View Struts tag.
Java Server Faces Model/View/Controller Design Pattern for Web Development Slides adapted from “Core JavaServer Faces” by Geary and Horstmann and the J2EE.
ASP.NET Programming with C# and SQL Server First Edition
Apache Struts Technology A MVC Framework for Java Web Applications.
Introduction to JavaServer Faces Jeff Swisher Director of Consulting Services Dunn Solutions Group.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Java Enterprise Edition Java Web Development Structure of a web project Introduction to Web Applications The first project Introduction to Java Web Development.
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)
Java Beans.
CSC 2720 Building Web Applications Using Java Beans, Custom Tags and Tag Libraries in JSP pages.
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.
What Are Beans? beans are simply Java classes that are written in a standard format. A bean class must have a zero-argument (default) constructor. A bean.
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.
1 Lecture 24 George Koutsogiannakis Spring 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
CSCI 6962: Server-side Design and Programming Introduction to Java Server Faces.
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
Web applications using JavaServer Faces (JSF) A brief introduction 1JavaServer Faces (JSF)
JSF Introduction Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
® IBM Software Group © 2007 IBM Corporation JSP Expression Language
Struts J2EE web application framework “ Model 2 ” Model View Controller Controller Servlet Key features XML metadata Struts taglib Simplified form validation.
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
Fall CIS 764 Database Systems Design L8. Web ….
CS320 Web and Internet Programming Java Beans and Expression Language (EL) Chengyu Sun California State University, Los Angeles.
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)
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
Struts Framework Anna Paščenko. What is Struts?  An open source framework for building Java web applications.
CSC 2720 Building Web Applications Frameworks for Building Web Applications.
Chính phủ điện tử TS. Phạm Văn Tính Khoa CNTT, ĐH Nông Lâm TP.HCM
Apache Struts. J2EE Web Application using MVC design pattern Why MVC? Separate components = easier maintenance – Model component holds object data – View.
Slides © Marty Hall, book © Sun Microsystems Press 1 Using JavaBeans with JSP Core Servlets & JSP book:
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.
Implementation Struts Framework for well-architectured web applications Model-View-Controller design pattern.
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.
Chapter 14 Using JavaBeans Components in JSP Documents.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
APACHE STRUTS ASHISH SINGH TOMAR ast2124. OUTLINE Introduction The Model-View-Controller Design Pattern Struts’ implementation of the MVC Pattern Additional.
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.
Introduction to Server-Side Web Development Introduction to Server-Side Web Development Introduction to Server-Side Web JavaBeans; basic concepts and syntax.
Struts 2 Development. Topics  Roles in Struts Development  Control Flow  Actions  Struts 2 Views and Target  Struts 2 Custom Tags  Validation 
Introduction to Java Server Faces (covered topics) ● Reasons to use „Java Server Faces“ ● JSF application structure ● JSF component model ● JSF managed.
Intro to JavaServer Faces Mimi Opkins CECS 493 Fall 2016.
JSF Portlet Navigation and Event Listeners
JavaServer Faces: The Fundamentals
Presentation transcript:

JavaServer Faces Jeff Schmitt October 5, 2006

Introduction to JSF Presents a standard framework for building presentation tiers for web applications Provides a set of presentation user interfaces (UI) components Provides an event model for wiring the interactions between the UI and the application objects Unlike servlet API, does not focus on low-level HTTP request handling Included in J2EE framework IDE-friendly, can allow drag-drop UI coding

JSF Advantages Custom UI controls to create complex interfaces Event handling – events are invoked when forms are submitted. Events can respond to particular buttons, changes in values, user selections, etc. Managed beans –In JSP, you can use to automatically save request parameters in a bean. –JSF extends this capability and adds in several utilities, which greatly simplifies processing of request parameters JSF Expression Language for accessing bean properties and collection elements

JSF Advantages Form field validation and conversion –insure form values are in correct format –Convert from string to various other types XML and property file-based configuration allows changes to application without changing Java code Encourages consistent use of MVC throughout the application

JSF Disadvantages Steep learning curve -- requires large JSF API as well as JSP a nd servlet APIs Less transparent – much is going on that you cannot see Relatively new – less documentation and less support from IDE Less flexible -- cannot depart from the approach given by framework. Note: this consistency can be an advantage

JSF Sample Application Library book management system User login (borrower or librarian privileges) Librarian –Add a book –Check in a book Borrower and Librarian –View all available books –Review all books –Check out a book

Faces Servlet Configured in web.xml URL pattern: *.faces (typically) Servlet Intercepts request, processes request parameters, creates events that call user code XML configuration file: faces-config.xml –I18n –Navigation rules –Bean definitions Implements JSF Lifecycle (next slide)

JSF Lifecycle JSF creates “component tree” –Each element corresponds to a UI value Steps in processing request –1 Restore view –2 Apply request values –3 Process validations –4 Update model values –5 Invoke application –6 Render response

1 Restore view Matches request to a view definition, usually a JSP file Default view definition adds.jsp to the same request –/view/books.faces -> /view/books.jsp Build component tree based on the view definition –Used by all subsequent processing steps –An object hierarchy –State maintained across multiple requests

2 Apply request values Analyze HTTP parameters Map parameters to specific UI components on the page If no parameters, skip to step 6 Render request

3 Process validations Cycle through all of the input validations for the components If any validations fail –render page with original data –Warning messages may be displayed

4 Update model values If the validation process succeeds Underlying Java beans associated with each UI component are updated

5 Invoke application After the model has been updated Invoke any business-logic acions requested by the user Determine a result code to be used in 6 Render response

6 Render response Render a response for the user Depending on result code returned in 5 Invoke Application, –view the page that was originally requested –or render a different page

<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" " en ISBNValidator com.oreilly.jent.jsf.library.validator.ISBNValidator … faces-config.xml

Navigation rules First major part of faces-config.xml Second major part is Managed beans If faces-config.xml gets too big –Split it into parts –Add an initialization parameter in web.xml javax.faces.CONFIG_FILES –Good for large projects with multiple developers where each module has separate settings

Navigation rules Each navagation-rule is like a flowchart “if” with one entry and multiple labelled exits –A single to match the URI being processed –When control returns from the module named here, a result string is returned. For example: success, failure, verify, login –Multiple entries matches a string gives next URI to forward to

* login /login/index.jsp home /index.jsp viewbooks /view/listbooks.jsp Navigation rules

/index.jsp addbook /view/addbook.jsp adminbooks /view/adminbooks.jsp

Navigation rules /login/index.jsp success /login/success.jsp failure /login/index.jsp

Managed Beans Second section of faces-config.xml Glues the UI given by jsp files to the business logic of your application Are simply JavaBeans following standard rules –a zero-argument (empty) constructor -- either by explicitly defining such a constructor or omit all constructors –no public instance variables (fields) –use accessor methods instead of allowing direct access to fields –accessed through methods called getXxx and setXxx –If class has method getTitle that returns a String, class issaid to have a String property named title –Boolean properties use isXxx instead of getXxx – For more on beans, see

Managed Beans JSF beans also have action methods –Invoked by JSF in response to a user action or event –Contain the code that manipulates the data model behind your application –In STRUTS these are called the Action classes and have to be superclasses of Action Two kinds of managed beans, although no technical difference between the two –Model beans – focus on data model of application –Backing beans – focus on UI of the application

Managed Beans Beans have four possible scopes – not quite the same as JSP/servlet scopes Application – entire application shares a single instance Session – new instance of bean when new user begins accessing Request – new instance for each request Scopeless – accessed by other beans and garbage collected like any other java object when no longer referred to by any object

Managed beans library com.oreilly.jent.jsf.library.model.Library application usersession com.oreilly.jent.jsf.library.session.UserSession session loginform com.oreilly.jent.jsf.library.backing.LoginForm request

Managed beans addbookform com.oreilly.jent.jsf.library.backing.AddBookForm request bookdisplayform com.oreilly.jent.jsf.library.backing.BookDisplayForm session library #{library}

JSF Expression language Similar but not identical to JSP EL Allow reference to the managed beans –Retrieving values from beans –Telling JSF components which bean properties to update –In some cases, same expression does both General syntax: #{identifiers and modifiers} Example: –uses a JSF HTML-writing tag <h: –Same expression both retrieves value from bean and –Tells JSF where to store submitted value from form –Uses two beans

JSF EL – built-in objects applicationScope - containing all application-scope managed beans Cookie facesContext - the FacesContext instance associated with the current request header - a map with HTTP request headers, one value per name headerValues - a map with HTTP request headers, containing all values initParam - a map with HTTP request parameters, containing all values param - a map with HTTP request parameters, one value per name paramValues - a map with HTTP request parameters requestScope - a map containing all request-scope managed beans sessionScope - a map containing all session-scope managed beans view - the UIViewRoot object associated with the current request

The library application index.jsp –<f:view – -- no action attribute –usersession.currentUser.username –rendered – a button that appears only for librarian –<h:outputText –<h:commandButton –<h:commandLink

Navigation <h:commandButton action=addbook addbook /view/addbook.jsp

Navigation case wildcard Wildcards allow a set of rules that applies to outcomes originating from any view * /view/addbook.jsp

Navigation – dynamic actions Control navigation based on outcomes confirmCredentials() -- a method in the backing bean associated with login Returns a string “success” or “failure”