JavaServer Faces. Objectives To implement dynamic web pages with JavaServer Faces (JSF) technology To learn the syntactical elements of JavaServer Faces.

Slides:



Advertisements
Similar presentations
WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
Advertisements

Java Script Session1 INTRODUCTION.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
The Web Warrior Guide to Web Design Technologies
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Chapter 27 JavaServer Pages and Servlets. Chapter Goals To implement dynamic web pages with JavaServer Faces (JSF) technology To learn the syntactical.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Internet Technologies 1 Master of Information System Management Java Server Faces Model/View/Controller Design Pattern for Web Development Slides.
JSP Tag Extensions And Java Bean. JSP Tag Extensions Tag extensions look like HTML (or rather, XML) tags embedded in a JSP page. They have a special meaning.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 3-1 of…
Computing Concepts Advanced HTML: Tables and Forms.
Java Server Faces Model/View/Controller Design Pattern for Web Development Slides adapted from “Core JavaServer Faces” by Geary and Horstmann and the J2EE.
Introduction To Form Builder
Tutorial 6 Forms Section A - Working with Forms in JavaScript.
UNIT-V The MVC architecture and Struts Framework.
CST JavaScript Validating Form Data with JavaScript.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
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.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
1 Forms A form is the usual way that information is gotten from a browser to a server –HTML has tags to create a collection of objects that implement this.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
XHTML Introductory1 Forms Chapter 7. XHTML Introductory2 Objectives In this chapter, you will: Study elements Learn about input fields Use the element.
Chapter 16 The World Wide Web. 2 The Web An infrastructure of information combined and the network software used to access it Web page A document that.
1 Introduction to JavaServerFaces & MyFaces Anudeep Jassal.
JDeveloper 10g and JavaServer Faces: High-Performance UIs on the Web Avrom Roy-Faderman Senior Programmer May, 2006.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 4-1 of…
10 Adding Interactivity to a Web Site Section 10.1 Define scripting Summarize interactivity design guidelines Identify scripting languages Compare common.
JavaServer Faces Jeff Schmitt October 5, Introduction to JSF Presents a standard framework for building presentation tiers for web applications.
Objectives: 1. Create a Skeleton HTML 2. View a Skeleton File Through a Server and Browser 3. Learn HTML Body Tags for the Display of Text and Graphics.
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.
CSCI 6962: Server-side Design and Programming Introduction to Java Server Faces.
Java Server Pages A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format,
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
CSCI 6962: Server-side Design and Programming Java Server Faces Components and Tags.
Chapter 34 Java Technology for Active Web Documents methods used to provide continuous Web updates to browser – Server push – Active documents.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
© 2010 Delmar, Cengage Learning Chapter 8 Collecting Data with Forms.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
Chapter 8 Collecting Data with Forms. Chapter 8 Lessons Introduction 1.Plan and create a form 2.Edit and format a form 3.Work with form objects 4.Test.
Java Server Faces Introduction Harshavardhan M. Karkar Project Manager Info-Spectrum India Pvt. Ltd.
Week 11 Creating Framed Layouts Objectives Understand the benefits and drawbacks of frames Understand and use frame syntax Customize frame characteristics.
Introduction to HTML Part 3 Chapter 2. Learning Outcomes Identify how to design frames. Explain frames’ attributes. Describe the method on designing forms.
Chapter 5: Windows and Frames
JavaScript - A Web Script Language Fred Durao
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
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 41 JavaServer Face.
CSCI 6962: Server-side Design and Programming JSF DataTables and Shopping Carts.
CSCI 6962: Server-side Design and Programming Facelets and User Interface Design.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
Week 10: HTML Forms HNDIT11062 – Web Development.
JavaServer Faces framework Craig McClanahan is presented that created Struts web framework and based on experience gathered designed JavaServer.
Introduction to HTML Simple facts yet crucial to beginning of study in fundamentals of web page design!
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
CSC 121 Computers and Scientific Thinking Fall Event-Driven Programming.
HTML Tutorial. What is HTML HTML is a markup language for describing web documents (web pages) HTML documents are described by HTML tags Each HTML tag.
Navigation Mimi Opkins CECS 493 Fall Static Navigation  In a simple web application, navigation is static. That is, clicking a particular button.
Section 10.1 Define scripting
Creating and Processing Web Forms
Objectives Design a form Create a form Create text fields
Chapter 27 WWW and HTTP.
Web Development Using ASP .NET
Presentation transcript:

JavaServer Faces

Objectives To implement dynamic web pages with JavaServer Faces (JSF) technology To learn the syntactical elements of JavaServer Faces To learn about navigation in JSF applications To build three-tier web applications

What is JSF? Bring graphical components to the Web Developers can think in terms of components, events, managed beans, and their interactions instead of request, responses, and markup language. Facelets is preferred PDL (page description language) of JSF 2.0

A Simple JSF Program JSF: Java Server Faces To develop a JSF application, you need a web server that is integrated with a JSF container A JSF page contains HTML and JSF tags The user interface of a JSF application is described by a set of JSF pages

A Simple JSF Program Page title Page contents Each JSF page has the following structure:

A Simple JSF Program Previous structure has three parts:  taglib directives required to locate two JSF libraries Tags from the core library have the prefix f: (such as f:view ) Tags from the HTML library have the prefix h: (such as h:form )  All JSF tags must be contained inside an f:view tag  The h:form tag encloses all user interface elements

File datetime/index.jsp 01: 02: 03: 04: 05: 06: 07: The datetime application 08: 09: 10: 11: Number of milliseconds since January 1, 1970: 12: 13: 14: 15: 16: 17:

Executing the datetime Web Application Figure 1: Executing the datetime Web Application

A Simple JSF Program Purpose of a JSF page is to generate an HTML page Basic process:  HTML tags in the page are retained; they are the static part of the page  JSF tags are translated into HTML; translation is dynamic, it depends on the state of Java objects The h: tags generate HTML The f: describe structural information that the h: tags use  The taglib directives are stripped out

The JSF Container Rewrites the Requested Page Figure 2: The JSF Container Rewrites the Requested Page

The HTML Code That Is Generated by a JSF Page Figure 3: The HTML Code That Is Generated by a JSF Page

A Simple JSF Program The JSF container converts a JSF page to an HTML page, replacing JSF tags with text and HTML In the example, the h:outputText tag has the value binding #{dateTime.time} Value bindings link JSF pages with Java objects Continued

A Simple JSF Program The Java objects are defined in a configuration file  Named faces-config.xml  Placed in the WEB-INF subdirectory of the web application's base directory

File datetime/WEB-INF/faces- config.xml 01: 02: 03: <!DOCTYPE faces-config PUBLIC 04: "-//Sun Microsystems, Inc. //DTD JavaServer Faces Config 1.0//EN" 05: " 06: 07: 08: 09: dateTime 10: java.util.Date 11: request 12: 13:

A Simple JSF Program This file defines an object dateTime with type java.util.Date A new object is constructed with each "request" Whenever a browser requests the page,  A new Date object is constructed, and  It is attached to the dateTime variable  The Date constructor constructs an object with the current time Continued

A Simple JSF Program #{dateTime.time} calls getTime of dateTime The h:outputText tag converts the result of that method call to text

Important Design Principle of the JSF Technology JSF enables the separation of presentation and business logic Presentation logic: the user interface of the web application Business logic: the part of the application that is independent of the visual presentation JSF pages define the presentation logic Java objects define the business logic The value bindings tie the two together

The Directory Structure of the datetime Application Figure 4: The Directory Structure of the datetime Application

File datetime/WEB-INF/web.xml 01: 02: 03: <!DOCTYPE web-app PUBLIC 04: "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 05: " 06: 07: 08: 09: FacesServlet 10: javax.faces.webapp.FacesServlet 11: 1 12: 13: 14: 15: FacesServlet 16: *.jsf 17: 18:

Self Check 1.What steps are required to add the image of a clock to the datetime application? (The clock doesn't have to show the correct time.) 2.Does a Swing program automatically separate presentation and business logic?

Answers 1.Place an image file, say clock.gif, into the datetime directory, and add a tag to the index.jsp file. 2.No–it is possible (and sadly common) for programmers to place the business logic into the frame and component classes of the user interface.

JSF Components Each component has a value attribute to connect the component value with a bean property h:inputTextArea has attributes to specify the rows and columns Continued

JSF Components Radio button and checkbox groups allow you to specify horizontal or vertical layout:

JSF Components: Button Groups and Menus Require two properties:  the collection of possible choices  the actual choice The value attribute specifies the actual choice to be displayed The collection of possible choices is defined by a nested f:selectItems tag Continued

JSF Components: Button Groups and Menus monthChoices must have a type that can describe a list of choices  For example, Map  The keys of the map are the labels  The corresponding map values are the label values

Example: Using a Map to Describe a List of Choices To create the list of choices: Continued public class CreditCardBean {... public Map getMonthChoices() { Map choices = new LinkedHashMap (); choices.put("January", 1); choices.put("February", 2);... return choices; } }

Example: Using a Map to Describe a List of Choices The type of the value property of the component must match the type of the map value  For example, creditCard.expirationMonth must be an integer If multiple selections are allowed, the type of the value property must be a list or array of matching types

Common JSF Components

Self Check 6.Which JSF components can be used to give a user a choice between "AM/PM" and "military" time? 7.How would you supply a set of choices for a credit card expiration year to a h:selectOneMenu component?

Answers 6. h:selectOneRadio, h:selectOneMenu, or h:selectOneCheckbox

Answers 7.You would need a bean with a property such as the following: Then supply a tag public Map getYearChoices() { Map choices = new TreeMap (); choices.put("2003", 2003); choices.put("2004", 2004);... return choices; }

Navigation Between Pages Consider a timezone program We start with a page that prompts the user to enter the name of a city When the user clicks " Submit " a new page appears Continued

Navigation Between Pages Next page is either the page with the time display or an error page if no time zone is available The JSF container needs to determine which page to show next

Navigating Between Pages Figure 9: Navigating Between Pages

Navigation Between Pages Each button has an outcome, a string used to look up the next page Generally, next page may depend on the result of some computation We need different outcomes depending on the city entered Continued

Navigation Between Pages Specify a method binding as the action attribute: A method binding consists of the name of a bean and the name of a method

Navigation Between Pages When the form is submitted, the JSF engine calls zone.addCity() public class TimeZoneBean {... public String addCity() { if (zone == null) return "unavailable"; // Add the city... return "available"; } Continued

Navigation Between Pages If next page doesn't depend on a computation, you set the action attribute of the button to a fixed outcome string

Navigation Between Pages available /next.jsp unavailable /error.jsp back /index.jsp... faces-config.xml contains a navigation rule that maps outcome strings to pages: Continued

Navigation Between Pages Current page is redisplayed when  The button has no action attribute, or  The action outcome is not listed in the navigation rules

Self Check 8.What tag would you need to add to error.jsp so that the user can click on a button labeled "Help" and see help.jsp ? What other changes do you need to make to the web application? 9.Which page would be displayed if the addCity method returned null ?

Answers 8.Add the tag to error.jsp, and add a navigation rule to faces-config.xml: 9.The current page would be redisplayed. help /help.jsp