a short overview 7/2/2015 1 © dipl.-inform. volker reichel, vrsoft, 2007

51
A short overview 03/16/22 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

Upload: bertha-harmon

Post on 21-Dec-2015

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

A short overview

04/19/23 1© Dipl.-Inform. Volker Reichel, VRSoft,

2007

Page 2: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

Seam is a web application framework based on JavaServer Faces which aims to simplify web development by reducing XML configuration tasks

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 POJO and JPA.

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft, 2007 2

Page 3: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

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 configuration hints

For feedback please send mail to [email protected]

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft, 2007 3

Page 4: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

Seam

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft,

2007 4

Page 5: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

04/19/23 5© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 6: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

04/19/23 6© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 7: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

Decide on how your Seam application will be deployed

04/19/23 7© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 8: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

Seam

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft,

2007 8

Page 9: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

JBoss Seam

04/19/23 9© Dipl.-Inform. Volker Reichel, VRSoft,

2007

Page 10: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

Form Backing BeansDirectly supported by JSFThe targets of JSF formsBring data into JSF pages

Action ListenerTarget of form submission & links Implementation of the MVC controllerPerforming business logic

Browser Accessible ComponentsAccessing EJBs or POJOs via JavaScript

(AJAX)

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft, 2007 10

Page 11: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

POJO StatelessSession Bean

StatefullSession Bean

EntityBean

Message DrivenBean

Component

++ -- ++ ++ -- Backing Bean

++ ++ ++ -- -- Action Listener

-- ++ ++ -- -- Browser Comp.

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft, 2007 11

Page 12: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

Container

and your

Seam Application

04/19/23 12© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 13: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

04/19/23 13© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 14: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

What needs to be done to get SEAM in place?

04/19/23 14© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 15: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

04/19/23 15© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 16: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

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

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

2. Configure FaceletsFaceletViewHandler (for basic Seam features)SeamFaceletViewHandler (enhanced JSF-EL, security)

3. Configure web application environmentSeam JSF Phase ListenerSeam Servlet Listener

4. Configure Seam features (optional)SeamFilter & Filter Mapping prepares Exception Handling & Validation

04/19/23 16© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 17: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

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

5. Configure EJB componentsSeamEJBInterceptorEJB Beans declarations (optional)

6. Enable optional Seam componentsSecurityPageflowjBPM

7. Define / Configure BehaviorActionsNavigationError HandlingConversation ManagementSecurity

continued

04/19/23 17© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 18: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

If you are developing a web application using a war-archive then put jboss-seam.jar in myapp/WEB-INF/lib directory

If 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.xmlReplace the highlighted regions according with your application

04/19/23 18© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 19: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

<?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>

04/19/23 19© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 20: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

Put JavaServer 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, security04/19/23 20© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 21: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

Seam needs to register itself with JSF in order to receive events during request processing. Therfore 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>

04/19/23 21© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 22: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

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>

04/19/23 22© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 23: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

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

04/19/23 23© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 24: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

<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>

04/19/23 24© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 25: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

Validation multi-part form submission Validation And other features are only available

when jboss-seam-ui is in the classpath of the webapp.Therefore you have to put jboss-seam-ui.jar into webapp/WEB-INF/lib directory.

04/19/23 25© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 26: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

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>

04/19/23 26© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 27: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

Step 5 is a necessary prerequisite for this step!

Components.xml is used to configure Seam components. Either predefined ones 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.

04/19/23 27© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 28: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

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 contents

04/19/23 28© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 29: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

Behavior is specified in pages.xml which is optional

There are Page actions

Trigger activity before a page is invoked Page navigation

Same 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

04/19/23 29© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 30: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

JBoss Seam

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft,

2007 30

Page 31: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

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

Session Spans the full HTTP-Session

Application Spans as long as the web application is running

Request Spans as long as the current HTTP-Request

Page Data belongs to the page

Conversation Spans across several HTTP-Requests

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

(more like a business process)

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft, 2007 31

Page 32: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft, 2007 32

Implicit Explicit

are default each request is wrapped in an implicit conversation

JSFPage

pages.xml

Java

@Begin / @End on method

f:param conversationPropagationor @propagation in seam:link-Element

@action=“#{conversation.XXXX}” in <page>-Element

Conversation.XXXbeginendjoinnest

Page 33: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

JBoss Seam

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft,

2007 33

Page 34: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft, 2007 34

RestoreView

Apply Request Values

ProcessValidation

s

UpdateModelValues

InvokeApplicatio

n

RenderResponse

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

Page 35: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

JBoss Seam

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft,

2007 35

Page 36: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

Seams Pageflow uses JBoss’s jBPMs Process Definition Language (jPDL)

jPDL has a different syntax than BPEL jPDL can be used to describe pageflows jPDL is different from <navigation-rule>-

Syntax jPDL consists of

StatesEvents / OutcomesTransitions

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft, 2007 36

Page 37: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

Can be mixed with JSF navigation By default disables “back” button

functionality Good for modal or wizard-driven UI flows Good separation of flow and UI

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft, 2007 37

Page 38: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

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

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft, 2007 38

Page 39: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft, 2007 39

State A

State B

Event E

Outcome X

JSF View

A

JSF View

B

ActionListener.actionMethod

Method return value

jPDL

JSF/Seam

Page 40: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

Seam

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft,

2007 40

Page 41: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

Provided as predefined component (identity)

Delegates implementation to user-defined class

Supports declarative security settings i.e. JRules (drools.jar)

Fine-grained security Finest level is method & instance

Needs facelets Needs jboss-seam-ui.jar in classpath Needs SeamFaceletViewHandler

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft, 2007 41

Page 42: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft, 2007 42

Pages ComponentsMethod

s

<page …> <restrict> </restrict></page>

<page login-required=“true”> …</page>

pages.xml

@Restrict annotationin Java Code either on class or individual method

*.java

Page 43: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft,

2007 43

Page 44: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

Seam

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft,

2007 44

Page 45: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft, 2007 45

JSF Page

JSF Page

JSF Page

JSF Page

POJO Facad

e

POJO Facad

e

Session EJB

Entity EJB

Session EJB

Entity EJB

Managed Bean

Automatically wrapped in Managed Bean

Page 46: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

Seam Features

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft,

2007 46

Page 47: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

Injection allows passing information from outside into an object

Injection is executed typically once during initialization of the object

Bijection passes information into an object and allows information to be exported from an object

Bijection happens whenever needed not only at initialization time

Bijections is controlled via @in / @out annotations

04/19/23© Dipl.-Inform. Volker Reichel, VRSoft, 2007 47

Page 48: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

04/19/23 48© Dipl.-Inform. Volker Reichel, VRSoft,

2007

Page 49: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

Situation JBoss 4.2.x and 5.x are using JSF Reference

Implementation (which is JSF 1.2) while 4.0.5 uses Apache MyFaces

Solution Make 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.xml

Make sure you are using the application and lifecycle settings provided on the next slide. Please check the namespace declaration and version attribute!

04/19/23 49© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 50: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

<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>

04/19/23 50© Dipl.-Inform. Volker Reichel, VRSoft, 2007

Page 51: A short overview 7/2/2015 1 © Dipl.-Inform. Volker Reichel, VRSoft, 2007

Software JBoss Seam http://labs.jboss.com/jbossseam

JBoss 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

04/19/23 51© Dipl.-Inform. Volker Reichel, VRSoft, 2007