1 Lecture 24 George Koutsogiannakis Spring 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES.

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
Tutorial 6 Creating a Web Form
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Chapter 51 Scripting With JSP Elements JavaServer Pages By Xue Bai.
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.
Struts Basics SSE USTC Qing Ding. Agenda What is and Why Struts? Struts architecture – Controller: Focus of this presentation – Model – View Struts tag.
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
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 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.
1 Guide to JSP common functions 1.Including the libraries as per a Java class, e.g. not having to refer to java.util.Date 2.Accessing & using external.
UNIT-V The MVC architecture and Struts Framework.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
CST JavaScript Validating Form Data with JavaScript.
JavaServer Faces: The Fundamentals Compiled from Sun TechDays workshops (JSF Basics, Web-Tier Codecamp: JavaServer Faces, Java Studio Creator; IBM RAD)
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
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,
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
Copyright © 2012 Accenture All Rights Reserved.Copyright © 2012 Accenture All Rights Reserved. Accenture, its logo, and High Performance Delivered are.
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.
JSP Java Server Pages Softsmith Infotech.
JavaServer Faces Jeff Schmitt October 5, Introduction to JSF Presents a standard framework for building presentation tiers for web applications.
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.
JSP Most of the web developers deploying web applications using servlets mixes the presentation logic and business logic. Separation of business logic.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
JSF Introduction Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
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.
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
Chapter 3 Servlet Basics. 1.Recall the Servlet Role 2.Basic Servlet Structure 3.A simple servlet that generates plain text 4.A servlet that generates.
16-Oct-15 JSP Implicit Objects. 2 JSP Implicit Objects are the Java objects that the JSP Container makes available to developers in each page and developer.
J2EE Overview Web Programming CSCI J2EE multi-tier architecture Servlet: Java class loaded into Web server JSP page: enhanced HTML page that is.
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)
1 HTML Forms
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
CSCI 6962: Server-side Design and Programming Java Server Faces Scoping and Session Handling.
A seminar on j2ee by saritha. s. What is J2EE J2EE (Java 2 Platform, Enterprise Edition) is a Java platform designed for the mainframe-scale computing.
Chính phủ điện tử TS. Phạm Văn Tính Khoa CNTT, ĐH Nông Lâm TP.HCM
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
1 Web Programming with Servlets & JSP ASSIGNMENT GUIDELINE.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
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.
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.
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.
Struts 2 Development. Topics  Roles in Struts Development  Control Flow  Actions  Struts 2 Views and Target  Struts 2 Custom Tags  Validation 
Navigation Mimi Opkins CECS 493 Fall Static Navigation  In a simple web application, navigation is static. That is, clicking a particular button.
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.
Event Handling Mimi Opkins CECS 493 Fall 2016.
J2EE Lecture 4: Advanced Concepts in JSF
JavaServer Faces: The Fundamentals
Presentation transcript:

1 Lecture 24 George Koutsogiannakis Spring 2011 CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES

Topics Java Server Faces – Continue from previous lecture- Standard Tags. – Using a managed bean. – Registering Listeners. – Creating a component with an event listener example. 2

Standard Tags (continued) Example of the View Tag Following is an example for the View Tag, that holds a Form Component, which in turn is having two Text Components along with a Submit Button. User name: Password: 3

Standard Tags (continued) Example of the View Tag In the previous slide the locale is set to Japanse ('ja' is the Locale Code name for Japanese) The Phase Listener interface is used to call before and after through the help of 'beforeMethod' and 'afterMethod' attributes. – afterPhase Handle a notification that the processing for a particular phase has just been completed. – beforePhase Handle a notification that the processing for a particular phase of the request processing lifecycle is about to begin. 4

Standard Tags (continued) Example of the View Tag By phase we mean a phase in the lifecycle of a request (see previous lecture slides). Let us review the lifecycle phases again: – Reconstitute Component Tree A JSP page in a JSF application is represented by a component tree. This phase starts the Lifecycle request processing by constructing this tree. Each component tree has an identifier that is unique throughout the application. The identifier of a component tree is the path information portion of the request URI. For a request with the URI /faces/index.jsp, for instance, the tree identifier is /index.jsp. The constructed component tree is then saved in the FacesContext object for processing by the following request processing phases. 5

Standard Tags (continued) Example of the View Tag – Apply Request Values In this phase, the local value of each component in the component tree is updated from the current request. A value can come from a request parameter, a header, a cookie, and so on. During this phase, a component may queue events. These events will be processed during the process event steps in the request processing lifecycle. 6

Standard Tags (continued) Example of the View Tag – Process Validations After the local value of each component is updated, in the Process Validations phase, the Lifecycle object will validate those values if necessary. A component that requires validation must provide implementation of the validation logic. Alternatively, a JSF programmer can register zero or more validators with the component. If one or more external validators are found, the local value of each component will be validated using the validation logic in these external validators. 7

Standard Tags (continued) Example of the View Tag – Update Model Values This phase can be reached only if the local values of all components in the tree are valid. In this phase, the Lifecycle object updates the application’s model data. During this phase, a component may again queue events. – Invoke Application During this phase, the JSF implementation handles any application level events, such as submitting a form or linking to another page. Render Response In this phase, the JSF implementation renders the response to the client. 8

Standard Tags (continued) Example of the SubView Tag Sub View represents a portion of the Display in the Entire Page. Sub View may be useful in situations where there is a need for a Main Page which is getting information fetched independently from Different Views. 9

Standard Tags (continued) Example of the SubView Tag If we wish to represent a portion of a JSP Page as a Sub View, then it has to be embedded into the Sub View Tag with the help of Import/Include Tags :, ), and then the Sub View Tag can be embedded within the View Tag. This Tag is identified by and following is the syntax definition for this Tag, 10

Standard Tags (continued) Example of the SubView Tag Assume that there is a Web Page contains several sections like Footer, Header and Advertisements along with other contents. Then subview will be one possible solution for such a kind of View Representation. Consider the following sample which illustrates this, 11

Standard Library Tags-Select tags Select Tags These are tags used to select Single or Multiple Entries from Select Components Like List-Box, Check-Box or a Radio-Button. – They usually appear as Child Tags under the Select Component Tags and they are used to represent and select Values. The identified Select tags are given as follows. Select Item Tag Select Items Tag 12

Standard Library Tags-Select tags – Example: – 13

Standard Library Tags-Select tags – Another Example: – 14

Standard Library Tags-Select tags The previous code populates a List-Box Component with Values like 'Summer Season', 'Winter Season', 'Spring Season' and 'Autumn Season'. Note that the value corresponding to 'itemLabel' attribute is the one that will be shown to the Clients. The actual value that is sent to the Server is the corresponding value of the attribute 'itemValue'. 15

Develop model Objects (Managed Bean) – It is the model (M) part in MVC – A regular JavaBeans with read/write properties – May contain application methods and event handlers – Use to hold data from a UI (page) – Creation and lifetime is managed by JSF runtime application, session, request – JSF keeps the bean's data in sync with the UI 16

Managed Bean Declaration (faces-config.xml) LoginFormBean myapp.LoginFormBean request 17

Create JSF Pages Must include JSF tag library – HTML and core tags – All JSF tags must enclosed between a set of view tag – Use JSF form and form component tags not – May include validators and event listeners on any form components 18

Sample JSF Page (login.jsp) <h:input_secret id=”password” length=”16” valueRef=”LoginFormBean.password”/> <h:command_button type=”submit” label=”Log On” actionRef=”LoginFormBean.logon”/> 19

Binding UI to Managed Bean Login.jsp 20 LoginFormBean myapp.LoginFormBean public class LoginFormBean... public void setUserName(...) { public String getUserName(...) { Faces-config.xml LoginFormBean.java

Define Page Navigation Rules (Faces-config.xml) /login.jsp success /menu.jsp /login.jsp failure /error.jsp 21

Registering Listeners on Components Listeners can be implemented either as classes – The listener id referenced from either a valueChangeListener tag or an actionListener tag and nest the tag inside the component tag or as backing beans – The method that implements the listener in the bean is referenced from either the component’s valueChangeListener attribute or its actionListener attribute. 22

Registering Listeners on Components The JSF event model is based on the event model defined by the JavaBeans specification. In this model, an event is represented by an instance of an event class. An event source object fires an event by calling an event notification method on event listener objects registered to receive the event, passing a reference to the event object as a notification method argument. 23

Registering Listeners on Components Classes that want to be informed about events are called event listeners. They declare which events they are interested in by implementing the corresponding listener interfaces. Hence, an event listener that wants to deal with the ActionEvent fired by a command component declares its intent like this: 24

Registering Listeners on Components The following phases of the request lifecycle can queue events in the FacesConext instance associated with the request: – Apply Request Values, – Process Validations, – Update Model Values, – Invoke Application Therefore, the JSF implementation must handle these events after these phases. Between two phases, the Lifecycle object checks any event listener that needs to be called. When writing an event listener, you can choose after which phase the listener should be executed. Alternatively, you can write an event listener that is called after various phases. 25

Registering Listeners on Components 26 Note that an event listener can change the course of the processing flow by indicating to the Lifecycle object that the processing should jump to the last phase or be terminated immediately after the current event processing.

Registering Listeners on Components A valueChangeListener tag can be inside a component tag The valueChangeListener tag supports two attributes: – type: References the fully qualified class name of a ValueChangeListener implementation – binding: References an object ( a backing bean) that implements ValueChangeListener – Component “name” has the listener class “NameChanged” registered with it. The field name in class cashier is set. 27

Registering Listeners on Components You can register (bind) a component to a java bean i.e. – valueRef attribute references the bean myBean – The UIOutput component :output_text receives its value form the resultproperty of the bean In the code below an ActionListener is registered with the command_button component: – You must of course write the java code for the listener class. 28

Creating a component with an event listener example Suppose that we have a simple jsp application where a form is generated and sent to the client. The form has input fields to accept two numbers and print the result of the addition of the two numbers. There is also a button that, when clicked, fires an ActionEvent and causes an event listener to be executed. – The event listener simply prints the names of the components in the component tree. 29

Creating a component with an event listener example The page sent to the client has has five user interface (UI) components: – a UIForm component, – two UIInput components, – a UIOutput component, – and a UICommand component The UIInput components and the UIOutput component are bound to a JavaBean – The bean stores the two input values and contains the logic of the addition. 30

Creating a component with an event listener example The request processing lifecycle always begins with the Reconstitute Component Tree phase. – In this phase, the Lifecycle object builds the component tree representing the requested page. – To be able to draw the tree, you need to create an event listener that will be called during one of the process event steps in the request processing lifecycle. 31

Creating a component with an event listener example Our application consists of the following parts: – A JSP page named adder.jsp – An NumberBean JavaBean for storing user data – An action listener called MyActionListener – A deployment descriptor (web.xml) – An application configuration file for registering the JavaBean faces-config.xml – A set of.jar files containing the JSF reference implementation and other libraries should be available ( or if you use NetBeans -they are available) 32

Creating a component with an event listener example If we assume that we are going to deploy this application in Tomcat we need a web app directory. The structure of the web app directory is shown on the next slide: 33

Creating a component with an event listener example 34

Creating a component with an event listener example The web.xml file has two important elements in it: – Faces Servlet javax.faces.webapp.FacesServlet 1 Faces Servlet /faces 35

Creating a component with an event listener example The servlet element registers the FacesServlet, and the servlet-mapping element states that any request containing the pattern /faces/ in the URL must be passed to the FacesServlet. FacesServlet is a servlet that manages the request processing lifecycle for web applications that are utilizing JavaServer Faces to construct the user interface. part of package: javax.faces.webapp.FacesServlet 36

Creating a component with an event listener example The code for the java bean needs to be created. public class NumberBean { int firstNumber = 0; int secondNumber = 0; public NumberBean () { } public void setFirstNumber(int number) { firstNumber = number; } public int getFirstNumber() { return firstNumber; } public void setSecondNumber(int number) { secondNumber = number; } public int getSecondNumber() { return secondNumber;} public int getResult() { return firstNumber + secondNumber;} } 37

Creating a component with an event listener example We can make the bean available to the application by registering it in the application configuration file faces-config.xml: – numberBean ch02a.NumberBean session 38

Creating a component with an event listener example The user interface consists of a JSP page called adder.jsp At the top of the jsp file call the taglibs for the html and core standard tag libraries (see previous letcure) Add 2 numbers First Number: 39

Creating a component with an event listener example Second Number: Result: 40

Creating a component with an event listener example Note that JSF controls (components) must be enclosed in the opening and closing elements:... Inside these elements, you have a form Inside the form you have: – two input_number controls, – an output_number control, – and a command_button control. The command button is registered with the ActionListener 41

Creating a component with an event listener example 42 The component tree of the adder.jsp page

Creating a component with an event listener example-when is event fired? The last step involves the generation of the code for the ActionListener: MyActionListener. ActionListener uses the ActionEvent class. The FacesEvent class—which all JSF events must extend either directly or through one of the standard subclasses, such as ActionEvent—defines a property named phaseId: 43

Creating a component with an event listener example-when is event fired? The phaseId property data type is PhaseId, which is a type- safe enumeration containing one value per request processing lifecycle phase: PhaseId.APPLY_REQUEST_VALUES, PhaseId.PROCESS_VALIDATIONS, PhaseId.UPDATE_MODEL_VALUES, PhaseId.INVOKE_APPLICATION, PhaseId.RENDER_RESPONSE, or PhaseId.ANY_PHASE. The PhaseId.ANY_PHASE value means "process the event in the phase where it was queued," and it's the default value for the phaseId property. 44

Creating a component with an event listener example-when is event fired? The UICommand always queues an ActionEvent in the Apply Request Values phase, – it also sets the phaseId to PhaseId.INVOKE_APPLICATION to delay the event handling – unless you tell it that you want to process it immediately. You do so through a UICommand property called immediate. If immediate is true, the phaseId is left unchanged so the event is processed in the Apply Request Values phase. 45

Creating a component with an event listener example-when is event fired? Most of the logic for keeping track of the phase in which an event is to be processed is implemented by the UIViewRoot component that sits at the top of the component tree. At the end of each phase, UIViewRoot goes through the event queue and calls the broadcast() method on all event source components. It starts with all events with phaseId set to PhaseId.ANY_PHASE and then the events queued for the current phase. It continues until there are no more events with these phaseId values in the queue, so if processing one event leads to a new event, the new event is also processed, as long as it's for a matching phase. 46

Creating a component with an event listener example Our class MyActionListener then will look like: import javax.faces.event.ActionListener; public class MyActionListener implements ActionListener {... public void processAction(ActionEvent e) throws AbortProcessingException { Implement the action associated with the event (In our case the drawing of the component tree)... } 47

Creating a component with an event listener example The ActionListener interface extends the javax.faces.event.FacesListener interface and defines one method, taking an ActionEvent instance as the single argument. Here is the definition of the ActionListener interface in the library: public interface ActionListener extends FacesListener { public void processAction(ActionEvent event) throws AbortProcessingException; } 48

Study Guide EE 5 Tutorial – Chapters 9, 10, 11 49