J2EE Lecture 4: Advanced Concepts in JSF

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
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
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.
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-02. Index. Jsp in Struts 2 Web.xml File in Struts 2.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
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)
1 Chính phủ điện tử TS. Phạm Văn Tính Khoa CNTT, ĐH Nông Lâm TP.HCM
Pittsburgh Java User Group– Dec Java PureFaces: A JSF Framework Extension.
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
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.
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.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
EJB Framework.  As we know, EJB is the center of the J2EE architecture that provides a sturdy framework for building enterprise applications. The major.
JSF road map (NI) Clientside validation Show problems
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.
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,
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.
CHEF II / Sakai Architecture. CHEF II Changes uPortal replaces Jetspeed –jsr 168 portlet, servlet compliant Spring replaces Turbine component framework.
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
Chapter 6 Server-side Programming: Java Servlets
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)
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.
JavaServer Faces (JSF) and Ajax Integration. Agenda 대강의 ( 정말로..) 개요 예제 아키텍트라면..
Internationalizing Sakai Raúl Mengod Universidad Politécnica de Valencia (Spain)
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.
© 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.
3246 JSF Support in JBuilder 2005 Karl Ewald R&D Engineer Borland Software Corporation.
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 4 Request and Response. Servlets are controlled by the container.
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.
PostBack  When an initial request for a page (a Web Form) is received by ASP.NET, it locates and loads the requested Web Form (and if necessary compiles.
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 
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.
Introduction to JavaServer Faces and the Woodstock UI Components Presenter Name
The Expression Language Syntax
J2EE Lecture 6: Spring – IoC and Dependency Injection
Event Handling Mimi Opkins CECS 493 Fall 2016.
J2EE Lecture 7: Spring – Spring MVC
Pre-assessment Questions
Knowledge Byte In this section, you will learn about:
JSF Portlet Navigation and Event Listeners
C# Event Processing Model
Objectives In this lesson you will learn about: Need for servlets
JavaServer Faces: The Fundamentals
J2EE Lecture 1:Servlet and JSP
J2EE Lecture 13: JMS and WebSocket
Presentation transcript:

J2EE Lecture 4: Advanced Concepts in JSF Dr. Ming Qiu Xiamen University Software School mingqiu@xmu.edu.cn

4.1 Creating and initializing beans JSF In Action, Chap 3 4.1 Creating and initializing beans Managed Bean Creation facility Declare all of your beans and initialize all of their properties in one central place. Control the scope (application, session, or request) where a bean is stored. Change a bean’s class or initial property values without changing any code. Initialize a bean property with value-binding expressions. Access a managed bean using ordinary JSF EL expressions.

4.1 Creating and initializing beans JSF In Action, Chap 3 4.1 Creating and initializing beans Creating and initializing beans Initializing simple properties Initializing List and array properties Initializing Map properties Declaring Lists and Maps as managed beans Setting values with value-binding expressions

<managed-bean> <managed-bean-name>brokeUser</managed-bean-name> <managed-bean-class>org.jia.examples.UserBean </managed-bean-class> <managed-bean-scope>request</managed-bean-scope> <managed-property> <property-name>firstName</property-name> <value>Joe</value> </managed-property> <property-name>lastName</property-name> <value>Broke</value> <property-name>balance</property-name> <value>0</value> <property-name>favoriteAnimal</property-name> <null-value/> </managed-bean> JSF In Action, Chap 3

<managed-bean> JSF In Action, Chap 3 <managed-bean> <managed-bean-name>user</managed-bean-name> <managed-bean-class>org.jia.examples.UserBean </managed-bean-class> <managed-bean-scope>request</managed-bean-scope> ... <managed-property> <property-name>favoriteSites</property-name> <list-entries> <value>http://www.jsfcentral.com</value> <value>http://www.theserverside.com</value> <value>http://www.ibm.com/developerworks/</value> <value>http://otn.oracle.com</value> <value>http://www.java.net</value> <value>http://www.manning.com</value> </list-entries> </managed-property> </managed-bean>

4.1 Creating and initializing beans JSF In Action, Chap 3 4.1 Creating and initializing beans <managed-bean> ... <managed-property> <property-name>favoriteNumbers</property-name> <list-entries> <value-class>java.lang.Integer</value-class> <value>31415</value> <value>278</value> <value>304</value> <value>18</value> <value>811</value> <value>914</value> </list-entries> </managed-property> </managed-bean>

<managed-bean> JSF In Action, Chap 3 <managed-bean> <managed-bean-name>user</managed-bean-name> <managed-bean-class>org.jia.examples.UserBean </managed-bean-class> <managed-bean-scope>request</managed-bean-scope> ... <managed-property> <property-name>favoriteSitesMap</property-name> <map-entries> <map-entry> <key>JSF Central</key> <value>http://www.jsfcentral.com</value> </map-entry> <key>TheServerSide.com</key> <value>http://www.theserverside.com </value>

<key>IBM DeveloperWorks</key> <map-entry> <key>IBM DeveloperWorks</key> <value>http://www.ibm.com/developerworks/ </value> </map-entry> <key>Oracle Technology Network</key> <value>http://otn.oracle.com</value> <key>java.net</key> <value>http://www.java.net</value> <key>Manning Publications</key> <value>http://www.manning.com</value> </map-entries> ... </managed-property> JSF In Action, Chap 3

4.1 Creating and initializing beans JSF In Action, Chap 3 4.1 Creating and initializing beans <managed-bean> <description>List of favorite sites.</description> <managed-bean-name>favoriteSites</managed-bean-name> <managed-bean-class>java.util.ArrayList</managed-bean-class> <managed-bean-scope>application</managed-bean-scope> <list-entries> <value>http://www.jsfcentral.com</value> <value>http://www.theserverside.com</value> <value>http://www.ibm.com/developerworks/</value> <value>http://otn.oracle.com</value> <value>http://www.java.net</value> <value>http://www.manning.com</value> </list-entries> </managed-bean>

4.1 Creating and initializing beans JSF In Action, Chap 3 4.1 Creating and initializing beans

JSF In Action, Chap 3

4.1Creating and initializing beans JSF In Action, Chap 3 4.1Creating and initializing beans A managed bean can’t reference an object with a shorter life span than the managed bean itself

4.1Creating and initializing beans JSF In Action, Chap 3 4.1Creating and initializing beans a scope of none means that the bean is created only when something else references it

4.2 Navigating the sea of pages JSF In Action, Chap 3 4.2 Navigating the sea of pages JSF supports navigating from one page to another. similar to Struts’ ActionForwards. The heart of the navigation system is the navigation handler The actual code that decides which page to load next operates in response to action events

4.2 Navigating the sea of pages JSF In Action, Chap 3 4.2 Navigating the sea of pages

4.2 Navigating the sea of pages JSF In Action, Chap 3 4.2 Navigating the sea of pages

4.2 Navigating the sea of pages JSF In Action, Chap 3 4.2 Navigating the sea of pages If you want to make sure that an outcome was generated by a specific action method <navigation-case> <from-action>#{orderManager.placeOrder}</from-action> <from-outcome>success</from-outcome> <to-view-id>/ConfirmOrder.jsp</to-view-id> </navigation-case>

4.2 Navigating the sea of pages JSF In Action, Chap 3 4.2 Navigating the sea of pages Set up rules for all pages or groups of pages. <navigation-rule> <from-view-id>*</from-view-id> <navigation-case> <from-outcome>login</from-outcome> <to-view-id>/login.jsp</to-view-id> </navigation-case> <from-outcome>logout</from-outcome> <to-view-id>/logout.jsp</to-view-id> </navigation-rule>

JSF In Action, Chap 11 4.3 From servlets to JSF JSF’s classes can be organized into four main categories Application access to supported locales, factory methods for UI components, access to the default message resource bundle. responsible for creating ValueBinding and MethodBinding instances, which can be used to evaluate JSF EL expressions in code.

4.3 From servlets to JSF Context Event handling UI components. JSF In Action, Chap 11 4.3 From servlets to JSF Context provide access to current request data, a handle to the outside environment, and entry to objects in other categories. Event handling responsible for processing user gestures In servlets, the request is the event. In JSF, request parameters are translated into event objects, and you can write listeners for processing those events. UI components.

JSF In Action, Chap 11

JSF In Action, Chap 11 4.3 From servlets to JSF The JSF Application class serve two important purposes. Provides access to configured parameters, like the set of supported locales, and the application’s message bundle. Provides factory methods for creating ValueBindings, MethodBindings, UIComponents, Validators, Converters, and so on. String bundleName = app.getMessageBundle(); ResourceBundle bundle = ResourceBundle.getBundle(bundleName, locale);

JSF In Action, Chap 11 4.3 From servlets to JSF Deprecated Deprecated

4.3 From servlets to JSF FacesContext JSF In Action, Chap 11 4.3 From servlets to JSF FacesContext has all the stuff you need to interact with the UI and the rest of the JSF environment. Retrieve a new Application instance from the FacesContext: FacesContext facesContext = FacesContext.getCurrentInstance(); Application app = facesContext.getApplication();

JSF In Action, Chap 11 4.3 From servlets to JSF

4.3 From servlets to JSF import javax.el.ExpressionFactory import javax.el.ELContext import javax.el.ValueExpression ExpressionFactory elFactory = application.getExpressionFactory(); ELContext elContext = facesContext.getELContext(); ValueExpression userExp = elFactory.createValueExpression(elContext, “#{user}”, User.class); User user = (User) userExp.getValue(elContext); Package javax.el is in JavaServer Pages API Documentation

4.4 Event handling JSF is event driven, JSF In Action, Chap 11 4.4 Event handling JSF is event driven, interaction with the user interface is represented as event objects that know what event occurred and which component sent it. This happens during the decoding the Apply Request Values phase saves you the trouble of reading request parameters to attempt to decipher what the user did.

4.4 Event handling Action listeners JSF In Action, Chap 11 4.4 Event handling Action listeners implement the javax.faces.event.ActionListener public void processAction(ActionEvent event) throws AbortProcessingException public class Foo{ public void nextPage(ActionEvent actionEvent){ // go to next page }

4.4 Event handling Action methods public String myAction(); JSF In Action, Chap 11 4.4 Event handling Action methods The default ActionListener instance invokes action methods based on the action property of the UI component firing the event. sends the action method’s outcome to the navigation handler. If the action property of the source component is a literal value instead of a method-binding expression, that value is used as the outcome. The navigation handler uses the outcome to set the proper page for JSF to display next public String myAction();

4.4 Event handling Handling value-change events JSF In Action, Chap 11 4.4 Event handling Handling value-change events When the local value of an input component changes and passes all validations, it fires an instance of the javax.faces.event.ValueChangeEvent. Occurs before any model objects have been updated, but after conversion and validation have taken place.

4.4 Event handling Value-change listeners JSF In Action, Chap 11 4.4 Event handling Value-change listeners public void processValueChange(ValueChangeEvent event) throws AbortProcessingException; public class Foo{ ... public void valueChange(ValueChangeEvent event){ // logic here }

JSF In Action, Chap 11 4.5 Components revisited

4.6 Understanding JSF development approaches JSF In Action, Chap 10 4.6 Understanding JSF development approaches The form-centric approach works well for small applications

4.6 Understanding JSF development approaches JSF In Action, Chap 10 4.6 Understanding JSF development approaches The object-based approach is more suitable for larger system, which need to be maintained for a long time