seminar.2008.jsf.seam

60

Upload: roialdaag

Post on 17-Dec-2014

637 views

Category:

Documents


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Seminar.2008.Jsf.Seam
Page 2: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

2

Java Server Facesadopting the standard

Roi Aldaag

Consultant, AlphaCSP

Page 3: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

3

Agenda

Introduction

Architecture

Configuration

Features

Pros & Cons

Page 4: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

4

Introduction

Not so long ago, if you “Googled“

the word JSF, you probably would

have come across …

Page 5: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

5

Introduction

The F-35 Joint Strike Fighter (JSF) …

Page 6: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

6

Introduction

Today you’d find…

JavaServer Faces Technology

Page 7: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

7

Introduction :: What is JSF?

What is JSF ?

Specification

UI framework

Component based

Server side

Java web applications

Page 8: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

8

Introduction :: Motivation

9 Billion Reasons for JSF…

Page 9: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

9

Introduction :: Motivation

JCP Standard

JSF 1.0/1.1 JSR 127 May 2005

JSF 1.2 JSR 252 May 2006

JSF 2.0 JSR 314 Q4 2008 ?

/ JEE6

Page 10: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

10

Introduction :: Motivation

Vendor adoption JSF RI

MyFaces

Page 12: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

12

Introduction :: Motivation

IDE integration Visual tool support

Drag & Drop

Auto-complete

Page 13: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

13

Introduction :: Motivation

Tools Component Libraries

IceFaces

RichFaces

ADF / Trinidad

Tomahawk

Extensions Facelets

Ajax4Jsf

DinoFaces

Page 14: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

14

Introduction :: Motivation

View Technology JSP / Servlet

Other template engines

Facelets

JSFTemplating

Multiple rendering output from same pages

Page 15: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

15

Introduction :: What is Seam?

What is Seam ? A lightweight framework for JEE5

Unifies JSF and EJB models(Web Beans / JSR 299)

Integrates JSF, POJOs, JPA, jBMP, Drools

Annotation / EL based

Extends JSF

JBoss OS (LGPL)

Release at 2006

Current version 2.0.2 SP1

Page 16: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

16

Introduction :: What is Seam?

Misconceptions Can be used without EJB3

Does not need a container

Has a small footprint

Easy integration

Page 17: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

17

Introduction :: Why JSF+Seam?

Why JSF + Seam? JSF has some weaknesses…

Seam extends and enhances JSF Reduces boilerplate code

Annotations

RESTful URLs

JSF Lifecycle

Contextual state management

Ajax Remoting

Exception Handling

Simple Integration EJB3 / jBMP/ Drools / Spring

Page 18: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

18

Introduction :: Seam in action

Page 19: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

19

Agenda

Introduction

Architecture

Configuration

Features

Pros & Cons

Page 20: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

20

Architecture :: JSF MVC

Front Servlet(FacesServlet)

Controller

Event Listeners &

Action Handlers(ValueChangeListener,

ActionListener)

Config(faces-config.xml)

Events(ValueChangeEvent,

ActionEvent)

ModelView

Component

Model(Java Beans)

Delegates(Convertors,

Validators,

Renderers)

Resources(JSP,

XML,

Properties)

Component

Tree(UIComponent)

Business

Objects(Managed Beans)

Request

Response

UIViewRoot

UIForm

UIInput UIInput

UIPanel

Model

View

Controller

Page 21: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

21

Architecture :: JSF MVC

Front Servlet(FacesServlet)

Controller

Event Listeners &

Action Handlers(ValueChangeListener,

ActionListener)

Config(faces-config.xml)

Events(ValueChangeEvent,

ActionEvent)

ModelView

Component

Model(Java Beans)

Delegates(Convertors,

Validators,

Renderers)

Resources(JSP,

XML,

Properties)

Component

Tree(UIComponent)

Business

Objects(Managed Beans)

Request

Response

UIViewRoot

UIForm

UIInput UIInput

UIPanel

Model

POJO’s

Page 22: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

22

Front Servlet(FacesServlet)

Controller

Event Listeners &

Action Handlers(ValueChangeListener,

ActionListener)

Config(faces-config.xml)

Events(ValueChangeEvent,

ActionEvent)

ModelView

Component

Model(Java Beans)

Delegates(Convertors,

Validators,

Renderers)

Resources(JSP,

XML,

Properties)

Component

Tree(UIComponent)

Business

Objects(Managed Beans)

Request

Response

UIViewRoot

UIForm

UIInput UIInput

UIPanel

Controller

Front Servlet

Configuration

Event Listeners

Architecture :: JSF MVC

Page 23: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

23

Architecture :: JSF MVC

Front Servlet(FacesServlet)

Controller

Event Listeners &

Action Handlers(ValueChangeListener,

ActionListener)

Config(faces-config.xml)

Events(ValueChangeEvent,

ActionEvent)

ModelView

Component

Model(Java Beans)

Delegates(Convertors,

Validators,

Renderers)

Resources(JSP,

XML,

Properties)

Component

Tree(UIComponent)

Business

Objects(Managed Beans)

Request

Response

UIViewRoot

UIForm

UIInput UIInput

UIPanel

View

Component Tree

Component Model

Delegates

Resources

Page 24: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

24

UIViewRoot

UIForm

UIInput UIInput

UIPanel

...

<f:view>

<h:form>

<h:panelGrid columns = "2">

<h:inputText/>

<h:inputSecret/>

</panelGrid>

</h:form>

</f:view>

..

HTML

JSP

WML

XML

Architecture :: Component Tree

MarkupComponent TreeJSF tags

Page 25: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

25

Architecture :: JSF Lifecycle

JSF Lifecycle1. Restore view

2. Apply request values

3. Process validations

4. Update model values

5. Invoke application

6. Render response

Restore View

Apply Request

Values

Process Validation

Update Model

Values

Invoke Appilcation

Render Response

Request

Response

Page 26: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

26

Architecture :: Seam Lifecycle

Seam Lifecycle1. Restore view

2. Restore Conversation

3. Apply Page Parameters

4. Apply request values

5. Process validations

6. Update model values

7. Invoke application

8. Process Selection

9. Store Conversation

10. Render response

Restore View

Apply Request

Values

Process Validation

Update Model

Values

Invoke Appilcation

Render Response

Request

Response

Store Conversation

Invoke Page Action

Process Data Model

Selection

Apply Page

Parameters

Restore

Conversation

Page 27: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

27

Architecture :: Seam Concepts

Seam Concepts1. Three Tier

2. POJOs and annotations

3. IoC and bijection

4. Contextual state management

5. Interceptors

Page 28: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

28

Agenda

Introduction

Architecture

Configuration

Features

Pros & Cons

Page 29: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

29

Configuration :: JSF

faces-config.xml

Page 30: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

30

Configuration :: Seam

faces-config.xml

Page 31: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

31

Configuration :: JSF

web.xml

Page 32: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

32

Configuration :: Seam

web.xml

Page 33: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

33

Agenda

Introduction

Architecture

Configuration

Features

Pros & Cons

Page 34: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

34

Features :: Demo JSF Project

LoginBean.java MasterDetailBean.java

jsfLogin.jsp jsfMasterDetail.jsp

faces-config.xmlweb.xml

/webproj

src

WebRoot

WEB-INF

managed

XML

XMLJSP

JSP

Page 35: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

35

Features :: Demo Seam Project

LoginBean.java MasterDetailBean.java

jsfLogin.jsp jsfMasterDetail.jsp

faces-config.xmlweb.xml

/webproj

src

WebRoot

WEB-INF

managed

lib

classes

XML

XML

JSP

JSP

seam.properties

jboss-seam.jar

jboss-seam-ui.jar

components.xml

Page 36: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

36

Features :: Demo Login page

jsfLogin.jsp

UIViewRoot

UIPanel

UIOutput

UIPanel

UIInput

UIForm

UIOutput

UIInput

UICommand

UIPanel

Page 37: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

37

LoginBean.java

Features :: JSF Value Binding

jsfLogin.jsp

faces-config.xml

Unified EL

Managed Bean

Page 38: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

38

LoginBean.java

Features :: JSF Method Binding

jsfLogin.jsp

Invoke Application

Phase

Page 39: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

39

Features :: JSF State Management

jsfLogin.jsp jsfMasterDetail.jsp

User

Dependency Injection

Page 40: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

40

Features :: Seam State Management

Contextual state management Bijection

@In - Injection

@Out – Outjection

Dynamic, contextual, bidirectional

Context Scope Event < Page < Conversation <

Business Process < Session < Application

Conversation Temporary conversation

Long-running conversation

ConversationId

Page 41: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

41

Features :: Seam State Management

MasterDetailBean.java

Page 42: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

42

LoginBean.java

Features :: JSF Page Flow

jsfLogin.jsp jsfMasterDetail.jsp

faces-config.xml

Page 43: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

43

Features :: Seam Page Flow

Page Actions HTTP GET

Bookmarking

RESTful URLs

HTTP POST

HTTP GET

Page 44: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

44

Features :: Seam Page Flow

Page Flow JBoss Business Process Management (jBPM)

Used to define process workflow / page flow

Define transition between pages

Define navigation rules for each page

Flow is based on events and conditions

Back button In conversation mode, back button is disallowed

Undefined transition

Seam blocks actions from “stale” pages

Redirects to relevant page

<<Start State>>

start

<<Page>>

login

<<Decision>>

User

authenticated ?

<<Page>>

contacts

true

<<End State>>

end

false

Page 45: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

45

Features :: JSF Validations

MasterDetailBean.java

jsfMasterDetail.jsp

Page 46: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

46

Features :: Seam Validations

jsfMasterDetail.jsp

MasterDetailBean.java

@org.hibernate.validator.Email

Page 47: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

47

Features :: JSF Error Handling

javax.servlet.ServletException: javax/servlet/jsp/tagext/JspIdConsumer

Page 48: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

48

Features :: Seam Error Handling

Page 49: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

49

Features :: Seam Error Handling

Exception Annotations

Page 50: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

50

Features :: Demo MasterDetail page

jsfMasterDetail.jsp

MasterDetailBean.java

Page 51: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

51

Features :: Demo MasterDetail page

jsfMasterDetail.jsp - continued

HtmlDataTable

HtmlColumn HtmlColumn

HtmlOutputText HtmlOutputText

Page 52: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

52

Features :: JSF Ajax

Ajax: Page Wide Page wide support (region, zone)‏

Add support to existing components

Sub view processing

Partial tree rendering

Normal lifecycle

Partial page refresh

Example:

Ajax4Jsf, Dynamic Faces

Page 53: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

53

Features :: JSF Ajax

Ajax: Component Wide Ajaxified components

Client validations

Client component interaction

Custom lifecycle

Example: RichFaces, IceFaces, ADF (Trinidad)‏

Page 54: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

54

Features :: Seam Ajax

Ajax Remoting Similar to DWR Access seam components from JS JavaScript APIs

Seam.Component Seam.Remote

Expose server side components @WebRemote

Compatible with Ajax4Jsf Dojo / GWT integration

Page 56: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

56

Agenda

Introduction

Architecture

Configuration

Features

Pros & Cons

Page 57: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

57

Pros & Cons

Seam Sweet spots Seam Gen (RoR)

Security (Role / Rule based)

Spring Integration

Integrated testing FW (TestNG)

Page 58: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

58

Pros & Cons

JSF Shortcomings Too much wiring

HTTP GET / REST is hard

Complicated Lifecycle

Slow learning curve

Writing new components

Poor exception handling

Page 59: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

59

References

JSF http://www.jcp.org/en/jsr/detail?id=252

http://jcp.org/en/jsr/detail?id=314

http://myfaces.apache.org/

Seam http://www.jboss.com/products/seam

http://www.seamframework.org/

Page 60: Seminar.2008.Jsf.Seam

Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

60

Thank

You !