jsf-seam

60

Upload: yuvalb

Post on 11-Apr-2015

797 views

Category:

Documents


2 download

DESCRIPTION

JSF & Seam presentation by Roi Aldag from AlphaCSP

TRANSCRIPT

Page 1: JSF-Seam
Page 2: JSF-Seam

2Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Java Server FacesJava Server Facesadopting the standardadopting the standard

Roi AldaagConsultant, AlphaCSP

Page 3: JSF-Seam

3Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

AgendaAgenda

Introduction Architecture Configuration Features Pros & Cons

Page 4: JSF-Seam

4Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Introduction Introduction

Not so long ago, if you “Googled“the word JSF, you probably would have come across …

Page 5: JSF-Seam

5Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Introduction Introduction

The F-35 Joint Strike Fighter (JSF) …

Page 6: JSF-Seam

6Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Introduction Introduction

Today you’d find…

JavaServer Faces Technology

Page 7: JSF-Seam

7Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Introduction :: What is JSF? Introduction :: What is JSF?

What is JSF ? Specification UI framework Component based Server side Java web applications

Page 8: JSF-Seam

8Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Introduction :: MotivationIntroduction :: Motivation

9 Billion Reasons for JSF…

Page 9: JSF-Seam

9Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Introduction :: MotivationIntroduction :: Motivation

JCP Standard

JSF 1.0/1.1 JSR 127 May 2005

JSF 1.2 JSR 252 May 2006JSF 2.0 JSR 314 Q4 2008 ?

/ JEE6

Page 10: JSF-Seam

10Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Introduction :: Motivation Introduction :: Motivation

Vendor adoption JSF RI MyFaces

Page 11: JSF-Seam

11Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Introduction :: Motivation Introduction :: Motivation

Popularity Commercial Projects Open Source Projects Market Documentation

Page 12: JSF-Seam

12Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Introduction :: MotivationIntroduction :: Motivation

IDE integration Visual tool support Drag & Drop Auto-complete

Page 13: JSF-Seam

13Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Introduction :: Motivation Introduction :: Motivation

Tools Component Libraries

IceFaces RichFaces ADF / Trinidad Tomahawk

Extensions Facelets Ajax4Jsf DinoFaces

Page 14: JSF-Seam

14Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Introduction :: Motivation Introduction :: Motivation

View Technology JSP / Servlet Other template engines

Facelets JSFTemplating

Multiple rendering output from same pages

Page 15: JSF-Seam

15Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Introduction :: What is Seam? 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: JSF-Seam

16Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Introduction :: What is Seam? Introduction :: What is Seam?

Misconceptions Can be used without EJB3 Does not need a container Has a small footprint Easy integration

Page 17: JSF-Seam

17Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Introduction :: Why JSF+Seam?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: JSF-Seam

18Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Introduction :: Seam in actionIntroduction :: Seam in action

Page 19: JSF-Seam

19Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

AgendaAgenda

Introduction Architecture Configuration Features Pros & Cons

Page 20: JSF-Seam

20Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Architecture :: JSF MVCArchitecture :: 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: JSF-Seam

21Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Architecture :: JSF MVCArchitecture :: 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: JSF-Seam

22Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

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 MVCArchitecture :: JSF MVC

Page 23: JSF-Seam

23Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Architecture :: JSF MVCArchitecture :: 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: JSF-Seam

24Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

UIViewRoot

UIForm

UIInput UIInput

UIPanel

...<f:view>< h:form>

< h:panelGrid columns = "2>"< h:inputText>/< h:inputSecret>/

/< panelGrid>/< h:form>/<f:view>

..

...<f:view>< h:form>

< h:panelGrid columns = "2>"< h:inputText>/< h:inputSecret>/

/< panelGrid>/< h:form>/<f:view>

..

HTMLHTML

JSP

WMLWML

XMLXML

Architecture :: Component TreeArchitecture :: Component Tree

MarkupComponent TreeJSF tags

Page 25: JSF-Seam

25Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Architecture :: JSF LifecycleArchitecture :: JSF Lifecycle

JSF Lifecycle1. Restore view2. Apply request values3. Process validations4. Update model values5. Invoke application6. Render response

Restore View

Apply Request Values

Process Validation

Update Model Values

Invoke Appilcation

Render Response

Request

Response

Page 26: JSF-Seam

26Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Architecture :: Seam LifecycleArchitecture :: Seam Lifecycle

Seam Lifecycle1. Restore view2. Restore Conversation3. Apply Page Parameters4. Apply request values5. Process validations6. Update model values7. Invoke application8. Process Selection9. Store Conversation10. Render response

Restore View

Apply Request Values

Process Validation

Update Model Values

Invoke Appilcation

Render Response

Request

ResponseStore Conversation

Invoke Page Action

Process Data Model Selection

Apply Page Parameters

RestoreConversation

Page 27: JSF-Seam

27Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Architecture :: Seam ConceptsArchitecture :: Seam Concepts

Seam Concepts1. Three Tier2. POJOs and annotations3. IoC and bijection4. Contextual state management5. Interceptors

Page 28: JSF-Seam

28Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

AgendaAgenda

Introduction Architecture Configuration Features Pros & Cons

Page 29: JSF-Seam

29Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Configuration :: JSFConfiguration :: JSF

faces-config.xml

Page 30: JSF-Seam

30Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Configuration :: SeamConfiguration :: Seam

faces-config.xml

Page 31: JSF-Seam

31Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Configuration :: JSFConfiguration :: JSF

web.xml

Page 32: JSF-Seam

32Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Configuration :: SeamConfiguration :: Seam

web.xml

Page 33: JSF-Seam

33Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

AgendaAgenda

Introduction Architecture Configuration Features Pros & Cons

Page 34: JSF-Seam

34Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Features :: Demo JSF ProjectFeatures :: 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: JSF-Seam

35Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Features :: Demo Seam ProjectFeatures :: 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: JSF-Seam

36Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Features :: Demo Login pageFeatures :: Demo Login page

jsfLogin.jsp

UIViewRoot

UIPanel

UIOutput

UIPanel

UIInput

UIForm

UIOutput

UIInput

UICommand

UIPanel

Page 37: JSF-Seam

37Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

LoginBean.java

Features :: JSF Value BindingFeatures :: JSF Value Binding

jsfLogin.jsp

faces-config.xml

Unified EL

Managed Bean

Page 38: JSF-Seam

38Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

LoginBean.java

Features :: JSF Method BindingFeatures :: JSF Method Binding

jsfLogin.jsp

Invoke ApplicationPhase

Page 39: JSF-Seam

39Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Features :: JSF State ManagementFeatures :: JSF State Management

jsfLogin.jsp jsfMasterDetail.jsp

User

Dependency Injection

Page 40: JSF-Seam

40Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Features :: Seam State ManagementFeatures :: 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: JSF-Seam

41Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Features :: Seam State ManagementFeatures :: Seam State Management

MasterDetailBean.java

Page 42: JSF-Seam

42Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

LoginBean.java

Features :: JSF Page FlowFeatures :: JSF Page Flow

jsfLogin.jsp jsfMasterDetail.jsp

faces-config.xml

Page 43: JSF-Seam

43Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Features :: Seam Page FlowFeatures :: Seam Page Flow

Page Actions HTTP GET Bookmarking RESTful URLs

HTTP POST

HTTP GET

Page 44: JSF-Seam

44Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Features :: Seam Page FlowFeatures :: 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: JSF-Seam

45Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Features :: JSF ValidationsFeatures :: JSF Validations

MasterDetailBean.java

jsfMasterDetail.jsp

Page 46: JSF-Seam

46Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Features :: Seam ValidationsFeatures :: Seam Validations

jsfMasterDetail.jsp

MasterDetailBean.java

@org.hibernate.validator.Email

Page 47: JSF-Seam

47Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Features :: JSF Error HandlingFeatures :: JSF Error Handling

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

Page 48: JSF-Seam

48Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Features :: Seam Error HandlingFeatures :: Seam Error Handling

Page 49: JSF-Seam

49Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Features :: Seam Error HandlingFeatures :: Seam Error Handling

Exception Annotations

Page 50: JSF-Seam

50Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Features :: Demo MasterDetail pageFeatures :: Demo MasterDetail page

jsfMasterDetail.jsp

MasterDetailBean.java

Page 51: JSF-Seam

51Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Features :: Demo MasterDetail pageFeatures :: Demo MasterDetail page

jsfMasterDetail.jsp - continued

HtmlDataTable

HtmlColumn HtmlColumn

HtmlOutputText HtmlOutputText

Page 52: JSF-Seam

52Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Features :: JSF AjaxFeatures :: 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: JSF-Seam

53Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Features :: JSF AjaxFeatures :: JSF Ajax

Ajax: Component Wide Ajaxified components Client validations Client component interaction Custom lifecycle Example:

RichFaces, IceFaces, ADF (Trinidad)

Page 54: JSF-Seam

54Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Features :: Seam AjaxFeatures :: 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 55: JSF-Seam

55Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Features :: DocumentationFeatures :: Documentation

JSF Specification Forums Books

Seam Reference Forums Books

Page 56: JSF-Seam

56Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

AgendaAgenda

Introduction Architecture Configuration Features Pros & Cons

Page 57: JSF-Seam

57Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Pros & ConsPros & Cons

Seam Sweet spots Seam Gen (RoR) Security (Role / Rule based) Spring Integration Integrated testing FW (TestNG)

Page 58: JSF-Seam

58Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Pros & ConsPros & Cons

JSF Shortcomings Too much wiring HTTP GET / REST is hard Complicated Lifecycle Slow learning curve Writing new components Poor exception handling

Page 59: JSF-Seam

59Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

ReferencesReferences

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: JSF-Seam

60Copyright AlphaCSP Israel 2008 – Web Framework Playoff Seminar

Thank Thank You !You !