0K - views

JBOSS Seam A technical overview

9/10/2007. 1. © Dipl.-Inform. Volker Reichel, VRSoft, 2007. Foreword. This presentation is not intended to provide a full description of all the features available in Seam.. It is the authors intend to present the key features and give some basic configuration hints in order to get a smooth start with Seam.

Embed :
Download Link

Download - The PPT/PDF document "JBOSS Seam A technical overview" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.

JBOSS Seam A technical overview






Presentation on theme: "JBOSS Seam A technical overview"— Presentation transcript:

Slide1

JBOSS Seam

A technical overview

9/10/2007

1

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Slide2

Foreword

This presentation is not intended to provide a full description of all the features available in Seam.It is the authors intend to present the key features and give some basic configuration hints in order to get a smooth start with Seam

Seam can be downloaded from http://labs.jboss.com/jbossseam/

For feedback please send mail to seam@vrsoft.de9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

2

Slide3

Introduction

Seam is a web application framework based on JavaServer Faces (JSF) which aims to simplify web development by reducing XML configuration tasks and Java helper classes.

Seam web applications can be deployed in EJB3 containers but this is not a must!Seam provides an embedded EJB3 container

Seam does not need EJB3 features at all. It works fine with Plain Old Java Objects (POJO) and Java Persistence Architecture

(JPA).

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

3

Slide4

Architecture

Seam

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

4

Slide5

Architecture

9/10/2007

5

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Slide6

Deployment Scenarios

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

6

Slide7

Deployment Scenarios

Decide on how your Seam application will be deployed

9/10/2007

7

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Slide8

Types of components

Seam

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

8

Slide9

Seam Component Types

Form Backing Beans (Java classes)Directly supported by JSF

The targets of JSF formsBring data into JSF pagesAction Listener (Java classes)

Target of form submission & linksImplementation of the MVC controllerPerforming business logicBrowser Accessible Components

(Java classes)

Accessing EJBs or POJOs via JavaScript (AJAX)

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

9

Slide10

Usage Best Practices

POJO

Stateless

Session BeanStatefullSession Bean

Entity

Bean

Message Driven

Bean

Component

++

--

++

++

--

Backing Bean

++

++

++

--

--

Action Listener

--

++

++

--

--

Browser Comp.

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

10

Slide11

Seam Features

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

11

Slide12

Seam features

Simplified Programming ModelNo more managed beansExtended state management

Supports structured pageflowPredefined flexible security componentSupports AjaxNo need to have an EJB3 container

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

12

Slide13

State management

JBoss Seam

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

13

Slide14

Seam Component Contexts

Contexts provide a mechanism for data access. Seam provides the following contexts:

SessionSpans a HTTP-SessionApplication

Spans as long as the web application is runningRequestSpans as long as the current HTTP-Request is runningPageData belongs to the page

Conversation

Spans across several HTTP-Requests

Workspace

Spans several sessions (i.e. users) and conversations

(more like a business process)

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

14

Slide15

Conversation Types

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

15

Implicit

Explicit

are default

each request is

wrapped in an implicit

conversation

JSF

Page

pages.xml

Java

@Begin / @End

on method

f:param

conversationPropagation

or

@propagation i

n

seam:link

-Element

@action=“#{

conversation.XXXX

}”

in <page>-Element

Conversation modes:

Conversation.begin

Conversation.end

Conversation.join

Conversation.nest

Slide16

Request Procession

JBoss Seam

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

16

Slide17

JSF Request Processing Phases

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

17

Restore

View

Apply Request Values

Process

Validations

Update

Model

Values

Invoke

Application

Render

Response

Determine target view & create / restore it

Update managed beans

Run application callbacks / action listeners

Refresh the view

Run registered

validators

Update UI components with request data

Slide18

Structured Pageflow

JBoss Seam

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

18

Slide19

Structured Pageflow

Seams Pageflow uses JBoss’s jBPMs

Process Definition Language (jPDL)jPDL has a different syntax than BPEL

jPDL can be used to describe pageflowsjPDL is different from <navigation-rule>-Syntax

jPDL

consists of

States

Events / Outcomes

Transitions

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

19

Slide20

JPDL Pageflow Features

Can be mixed with JSF navigationBy default disables “back” button functionalityGood for modal or wizard-driven UI flows

Good separation of flow and UI

9/10/2007© Dipl.-Inform. Volker Reichel, VRSoft, 2007

20

Slide21

Enabeling Pageflow (jBPM)

Add

<component class=“org.jboss.seam.core.Jbpm

”>

<property name=“

pageflowDefinitions

”>

<value>

flow_A.jpdl.xml

</value>

<value>

flow_B.jpdl.xml

</value>

</property>

</component>

to

components.xml

Put the flow file (

*.

jpdl.xml

) into the web apps

classpath

. For security reasons flows should be stored in

<

webapp

>/WEB-INF/classes

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

21

Slide22

Mapping jPDL

To JSF/Seam9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

22

State A

State B

Event E

Outcome X

JSF View

A

JSF View

B

ActionListener.actionMethod

Method return value

jPDL

JSF/Seam

Slide23

Security

Seam

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

23

Slide24

Security

Provided as predefined component (identity)Delegates implementation to user-defined Java class

Supports declarative security settingsi.e. JRules (drools.jar)Fine-grained security

Finest level is method & instanceNeeds faceletsNeeds

jboss-seam-ui.jar

in

classpath

Needs SeamFaceletViewHandler

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

24

Slide25

Protection Levels

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

25

Pages

Components

Methods

<page …>

<restrict>

</restrict>

</page>

<page

login-required=“true”>

</page>

pages.xml

@Restrict annotation

in Java Code either on

class or individual method

*.java

Slide26

SEAM Application Configuration

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

26

Slide27

SEAM Application Configuration

What needs to be done to get a Seam application running?

Configure EJB componentsSeamEJBInterceptor

EJB Beans declarations (optional)Enable optional Seam components

Security

Pageflow

jBPM

Define / Configure Behavior

Actions

Navigation

Error Handling

Conversation Management

Security

continued

9/10/2007

27

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Slide28

SEAM Application Configuration

What needs to be done to get a Seam application running?

Bundle Seam core libraries with your application (ear or war)

The details will be given laterConfigure Facelets

FaceletViewHandler (for basic Seam features)

SeamFaceletViewHandler (enhanced JSF-EL, security)

Configure web application environment

Seam JSF Phase Listener

Seam Servlet Listener

Configure Seam features (optional)

SeamFilter & Filter Mapping prepares Exception Handling & Validation

9/10/2007

28

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Slide29

1. Bundle Seam core libraries

If you are developing a web application using a war-archive then put

jboss-seam.jar in webapp

/WEB-INF/lib directoryIf you are developing an enterprise application (ear) then put jboss-seam.jar in root of the EAR archive and reference the

jboss-seam.jar

module as shown on the next slide in your

application.xml

Replace the text in the highlighted regions according with your application

9/10/2007

29

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Slide30

Application.xml

<?xml version="1.0" encoding="UTF-8"?><application

xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd"

version="5">

<display-name>

MyApp

</display-name>

<module>

<web>

<web-

uri

>

myapp.war

</web-

uri

>

<context-root>/

myapp

</context-root>

</web>

</module>

<module>

<

ejb

>

myapp-ejb.jar

</

ejb

>

</module>

<!-- Seam and EL -->

<module>

<java>jboss-seam.jar</java>

</module>

</application>

9/10/2007

30

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Slide31

2. Configure Facelets

PutJavaServer

Faces (jsf-facelets.jar)Expression Language API (el-api.jarEL-Reference Implementation (el-ri.jar)into your

webapp classpath i.e. WEB-INF/lib

Set view-handler in

faces-config.xml

to

com.sun.facelets.FaceletViewHandler

If you want basic

Facelet

support

org.jboss.seam.ui.facelet.SeamFacletViewHandler

If you want enhanced features like JSF EL, validation, security

9/10/2007

31

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Slide32

3. Configure web application

EnvironmentSeam needs to register itself with JSF in order to receive events during request processing. Therefore we have to add a SeamPhaseListener to

faces-config.xml.

<faces-

config

>

<lifecycle>

<phase-listener>

org.jboss.seam.jsf.SeamPhaseListener

</phase-listener>

</lifecycle>

</faces-

config

>

9/10/2007

32

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Slide33

3. Configure web application

Environment

Seam contexts and core services are managed by a SeamServletListener which you have to setup in web.xml.

<web-app>

<listener>

<listener-class>

org.jboss.seam.servlet.SeamListener

</listener-class>

</listener>

</web-app>

9/10/2007

33

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Slide34

4. Configure Seam features

Some Seam features which can be configured in

components.xml need a basic web filter you have to add the definitions shown on the next slide to

web.xml

9/10/2007

34

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Slide35

<web-app> …

<servlet>

<servlet-name>Seam Resource Servlet</servlet-name>

<servlet-class>org.jboss.seam.servlet.ResourceServlet</servlet

-class>

</

servlet

>

<

servlet

-mapping>

<

servlet

-name>Seam Resource Servlet</

servlet

-name>

<

url

-pattern>/seam/resource/*</

url

-pattern>

</

servlet

-mapping>

<filter-name>Seam Filter</filter-name>

<filter-class>

org.jboss.seam.web.SeamFilter

</filter-class>

</filter>

<filter-mapping>

<filter-name>Seam Filter</filter-name>

<

url

-pattern>/*</

url

-pattern>

</filter-mapping>

…</web-app>

9/10/2007

35

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

web.xml

Slide36

4. Configure Seam features

ValidationMulti-part form submission

SecurityAnd other features are only available when jboss-seam-ui.jar is in the

classpath of the webapp.Therefore you have to put

jboss-seam-ui.jar

into

webapp

/WEB-INF/lib

directory.

9/10/2007

36

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Slide37

5. Configure EJB components

In order to use Seam EJB components you have to install the Seam EJB Interceptor which is done your

ejb-jar.xml file.

<

ejb

-jar>

<assembly-descriptor>

<interceptors>

<interceptor>

<interceptor-class>

org.jboss.seam.ejb.SeamInterceptor

</interceptor-class>

</interceptor>

<interceptor-binding>

<

ejb

-name>*</

ejb

-name>

<interceptor-class>

org.jboss.seam.ejb.SeamInterceptor

</interceptor-class>

</interceptor-binding>

</assembly-descriptor>

</

ejb

-jar>

9/10/2007

37

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Slide38

6. Enable Optional Seam

componentsStep 5 is a necessary prerequisite for this step!

components.xml is used to configure Seam components. Either predefined or your own components.Typically you will only enable predefined components like security here.

Your own components are made accessible via the @Name annotation in your source! But if you like you can configure your components here also.

9/10/2007

38

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Slide39

6. Enable Optional Seam

components

If you are going with EJB 3.0 you have to provide a JNDI pattern for the lookup of these EJBs.

<components>

<component name=“

org.jboss.seam.core.init

”>

<property name=“

jndiPattern

”>

myApp

/#{

ejbName

}/local</property>

</component>

</components>

#{

ejbName

} will expand

to your EJB’s name during runtime

Make sure

seam.properties

is in your META-INF directory. The file does not need to have any contents but if it is missing the automatic scanning for components will not work!

9/10/2007

39

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Slide40

7. Define / Configure Behavior

Behavior is specified in

pages.xml which is optionalThere arePage actionsTrigger activity before a page is invoked

Page navigationSame as navigation rules in faces-config.xml

Since

faces-config.xml

is for Facelets page navigation should be defined here for consistency

Error handling

redirect to a page, show JSF message, end conversation

Manage conversation properties

Start, end

Security

declare security constraints on pages, roles, users

9/10/2007

40

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Slide41

Simplified Programming Model

Seam

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

41

Slide42

JSF vs. SEAM

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

42

JSF Page

JSF Page

JSF Page

JSF Page

POJO Facade

POJO Facade

Session EJB

Entity EJB

Session EJB

Entity EJB

Managed Bean

Automatically wrapped in Managed Bean

Slide43

Injection & Bijection

Seam Features

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

43

Slide44

What is injection /

Bijection?Injection allows passing information from outside into an object

Injection is executed typically once during initialization of the objectBijection passes information into an object and allows information to be exported from an object

Bijection happens whenever needed not only at initialization timeBijections is controlled via @in / @out annotations

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

44

Slide45

Special Notes for JBOSS Application Server

9/10/2007

45

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Slide46

JBOSS 4.2.x / JBOSS 5.X

SituationJBoss 4.2.x and 5.x are using JSF Reference Implementation (which is JSF 1.2) while 4.0.5 uses Apache MyFaces

SolutionMake sure “MyFaces” listener (org.apache.myfaces.webapp.StartupServletContextListener) is commented out in the listener sections of web.xml

Remove “el-ri.jar” and “el-api.jar” from application.xmlMake sure you are using the application and lifecycle settings provided on the next slide. Please check the namespace declaration and version attribute!

9/10/2007

46

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Slide47

Sample faces-config.xml for 4.2.x and 5.x

<faces-config version="1.2"

xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">

<application>

<el-resolver>

org.jboss.seam.jsf.SeamELResolver

</el-resolver>

</application>

<lifecycle>

<phase-listener>

org.jboss.seam.jsf.SeamPhaseListener

</phase-listener>

</lifecycle>

<!-- more configurations go here -->

</faces-

config

>

9/10/2007

47

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Slide48

Resources

SoftwareJBoss Seam

http://labs.jboss.com/jbossseamJBoss AS http://labs.jboss.com/jbossas

BooksPractical JBoss Seam Projects, Jim Farley, Apress

JBoss Seam Simplicity and Power Beyond Java EE

, Michael

Juntao

Yuan & Thomas

Heute

, Prentice Hall

9/10/2007

48

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Slide49

Revision history

02.09.2007

Initial version

03.09.2007Review

9/10/2007

© Dipl.-Inform. Volker Reichel, VRSoft, 2007

49