35
JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014

JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

Embed Size (px)

Citation preview

Page 1: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

JSF FrameworkJava Server Faces

Presented by Songkran Totiya (6/10/2014)

Page 2: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

2

Agenda

•What is and why JSF?•Architecture Overview •UI Component Model•Development Steps•Introducing Primefaces•Q & A

Page 3: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

3

JavaServer™ Faces (JSF) Framework Is…

A server side user interface component framework for Java™

technology-based web applications

Page 4: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

4

What is JSF?

•A specification and reference implementation for a web application development framework- Components- Events- Validators & converters- Navigation- Back-end-data integration

Page 5: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

5

Why JSF? (page 1)

•MVC for web applications•Clean separation of roles•Easy to use•Extendable Component and Rendering

architecture•Support for client device independence•Standard•Huge vendor and industry support

Page 6: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

6

Why JSF? (page 2)• JSP and Servlet

– No built-in UI component model• Struts (I am not saying you should not use

Struts)– No built-in UI component model– No built-in event model for UI components– No built-in state management for UI components– No built-in support of multiple renderers – Not a standard (despite its popularity)

• Struts and JSF can be used together

Page 7: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

7

JSF Architecture [MVC]

Page 8: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

8

Request processing Lifecycle

Page 9: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

9

Request Processing Lifecycle Phases

Page 10: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

10

Request Processing Lifecycle

Page 11: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

11

Request Processing LifecyclePhases1.Reconstitute component tree phase2.Apply request values phase3.Process validations phase4.Update model values phase5.Invoke application phase6.Render response phase

Page 12: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

12

User Interface Component Model•UI components•Event handling model•Conversion and Validation model•Rendering model•Page navigation support

Page 13: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

13

UI Components

•UIComponent/UIComponentBase- Base class for all user interface components

•Standard UIComponent Subclasses- UICommand, UIForm, UIOutput- UIGraphic, UIInput, UIPanel, UIParameter- UISelectBoolean, UISelectMany, UISelectOne

•Example:

Page 14: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

14

Validators and Converters• Validators - Perform correctness checks on

UIInput values- Register one or more per component- Enqueue one or more messages on errors- Standard implementations for common cases

• Converters - Plug-in for conversions:- Output: Object to String- Input: String to Object- Standard implementations for common cases

Page 15: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

15

Converters and Validators

•Example:

Page 16: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

16

Rendering Model

Renderers-Adapt components to a specific markup language

•Decoding•EncodingRenderKits—Library of Renderers•Map component classes to component

tags•Is a custom tag library•Basic HTML RenderKit

Page 17: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

17

Events and Listeners

•Follows JavaBeans™ Specification design and naming patterns

•Standard events and listeners▫ActionEvent—UICommand component

activated by the user▫ValueChangedEvent—UIInput component

whose value was just changed

Page 18: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

18

Navigation Model

•Application developer responsibility▫Defined in Application configuration

file(Facesconfig.xml)•Navigation rules

▫Determine which page to go.▫Navigation case

Page 19: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

19

Navigation Model

Page 20: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

20

Steps in Development Process1. Develop model objects which hold the data

2. Add model objects (managed bean) declarations to Application Configuration File faces-config.xml

3. Create Pages using UI component and core tags

4. Define Page Navigation in faces-config.xml

5. Configure web.xml

Page 21: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

21

Step1: Develop model Objects (Managed Bean)

•The model (M) 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

Page 22: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

22

Step 2. Managed Bean Declaration(Faces-config.xml)

Page 23: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

23

Step 3: 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▫<h:input_text> not <input type=”text”>▫<h:command_button> not <input

type=”submit”>• May include validators and event listeners on

any form components

Page 24: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

24

Sample JSF™ Page (login.jsp)

Page 25: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

25

Binding UI to Managed Bean

Page 26: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

26

Step 4: Define Page Navigation Rules(Faces-config.xml)

Page 27: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

27

Step 5: Configure (web.xml)

Page 28: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

28

JSF Application directory structure

Page 29: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

29

Introducing Primefaces

•Ready For PrimeTimePrimeFaces is a popular open source framework for JavaServer Faces featuring over 100 components, touch optimized mobilekit, push framework, client side validation, theme engine and more.

• http://www.primefaces.org/showcase/

Page 33: JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)

33

Summary

•JSF: Server side UI component framework•MVC•Developing application in JSF•Primefaces Ajax component framework