Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model •...

42
Introduction to JBoss Seam Sebastien Degardin [email protected] http://www.seamframework.org

Transcript of Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model •...

Page 2: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

Agenda

• What is Seam ?, The goal of this talk• Java EE 5 Programming Model

• Java Server Faces (JSF)

• Enterprise Java Bean 3.0 (EJB)

• Example Application

• What can be improved

• Seam• Key features

• Demo With JBoss Developer Studio

• The Contextual Component Model

• Bijection

• Demo

• Conversations and Workspace management

• Demo

• Seam and Object/Relational Mapping

• Demo

Page 3: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

Agenda

• Seam• JSF Validation in Seam

• Demo

• Security

• Demo

• Pageflows and Business Processes

• Event, Interceptors and Exceptions

• Demo

• Email

• Demo

• Testing Seam applications

• Demo

• Seam and others frameworks

• What’s coming

• Questions

• References

Page 4: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

What is Seam

• Seam is an application framework for Java EE 5 that simplify the development of web application”• Unify the 2 main Component models in Java EE 5, EJB 3.0 &

JSF

• Designed for Stateful Application

• Design with ORM in mind

Page 5: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

Java EE 5

• Java EE 5 is a major step forward from J2EE

• Java Server Faces

• EJB 3.0

Page 6: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

Java Server Faces

• Component Based MVC

• Component model for widget

• Embedded in Template language

• No more JSP, Facelets

• Component model for application logic, Managed Bean

• JavaBean component with xml deployment descriptor

• Stateful component attached to a context (request/session/application)

• EL for mapping between the 2 component models

• Other stuff like Validators and Converters

Page 7: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

EJB 3.0

• Transaction• Declarative Transaction Management

• Transaction Propagation

• Persistence• JPA, Java Persistence 1.0

• Persistence Context, Extended Persistence Context (for Optimistic Transaction)

• Interceptor for AOP

• Others Services• Concurrency, Security, Distributed Object, Asynchronous

Messaging, Naming, Timer Services

Page 8: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

EJB 3.0

• Stateful Session Bean

• Stateful Component that can be clustered

Page 9: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

Example ApplicationA Java EE 5 Application

Page 10: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

Entity BeanMark the Class

as an Entity

All entity must have an Id

Define the DatabaseConstraints using

Hibernate Validators

Page 11: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

Stateless Session Bean

The PC is injected

Mark the Classas Stateless

Session Bean

Page 12: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

JSF Search Page

Page 13: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

The JSF Life Cycle

Page 14: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

JSF Edit Page

Page 15: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

JSF Managed Bean

Page 16: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

Managed Bean Deployment Descriptor

Page 17: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

Navigation Rules

Page 18: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

What can be improved

• The concern of the Managed Bean is “Glue”• Layering is useful but does not have to be the first priority and

should not be imposed by the spec

• The Backing Bean isolate the Presentation from the Business Tier in a Wrong Way

• Calling the Session Bean directly make sense,

• Validation in JSF, Backing Bean and Entity Bean

• XML in JSF is very verbose

Page 19: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

What can be improved

• HttpSession is not the right place to store application state

Page 20: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

JBoss Seam

Page 21: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

Key Features of Seam

• Unify the 2 components Models• Remove the JSF Backing Bean

• Connect the Session Bean to the View

• No more verbose XML

Page 22: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

Key Features of Seam

• Natural Period of user Action

• Multi-tab with the conversation context

• WorkFlow, Wizard (stateful navigation)

• Business Process Management ( ex: Amazon order)

Page 23: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

DEMO

• Create a Seam application with JBoss Developer Studio

• First Application tour

• JBoss Developer Studio

• The project skeleton

• The Facelets template

• Login/logout functionality

Page 24: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

The Contextual Component Model

• The 3 built-in contexts are not especially meaningful from the point of view of the business logic

• Most components are scoped to the conversation or the Business Process context

• Contexts are created and destroyed by the framework or in some case via annotation

Page 25: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

The Contextual Component Model

• Seam Contexts• Stateless context

• Event context (request)

• Page context• attached to the page, useful for clickable list, ...

• Conversation context• one of the most powerful concept provided by Seam

• Session Context

• Business process context• longer than session, (eBay auction)

• Application Context

Page 26: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

The Contextual Component Model

• Seam component• Stateless Session Bean (SLSB)

• Stateful Session Bean (SFSB)

• Entity Bean

• Java Bean

• Message Driven Bean (MDB)

• Interception

Page 27: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

Bijection

• Seam emphasizes the concept of Stateful component, traditional DI is no longer very useful

• Bijection is : • Contextual, assembles various component from different context.

(even from narrower context)

• Bidirectional, values are injected from the context variables when the component is invoked and outjected back into the context variables.

• Dynamic, since values of contextual variable changes over time and since component are stateful, bijection takes place every time a component is invoked

Page 28: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

DEMO

• Seam Contextual Component Model

• Bijection

Page 29: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

Seam and Persistence

• Introduction• The optimistic transaction problem

• The EJB 3.0 improvement

• Seam’s solution

• Seam managed transactions• Seam managed persistence context

Page 30: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

JSF Validation in Seam

• The DRY Concept• JSF Tags

Page 31: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

DEMO

• Seam Validation

• Seam’s JSF Validation Tags

Page 32: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

Security in Seam

• Simple security• Advanced Security using JBoss Rules (Drools)

Page 33: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

Other Stuff

• Email Using Facelets Template• PDF Using Facelets Template

Page 34: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

Other Stuff

• Remoting• Web Services• Portal• Integration with different App Servers

Page 35: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

Seam and Other Frameworks

• Seam and GWT

• Seam and Spring

• Sean and Wicket

• Seam and Adobe Flex

• Groovy Integration

Page 36: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

What’s coming

• JAVA EE 6.0 (JSR 316)

• EJB 3.1 (JSR 220)

• JPA 2.0 (JSR 317)

• JSF 2.0 (JSR 314)

• Web Beans (JSR 299)

Page 37: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

EJB 3.1 New Features

• EJB Interfaces are Optional• Singleton Bean (@Singleton)• Concurrency• Direct use in the Servlet container (War file)• Stateful Web Services using SFSB

Page 38: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

JPA 2.0

• More flexible Model• Support for Collection of basic type (String, ...)• @OrderedList• Bean Validation (JSR 303)

Page 39: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

Questions ?

Page 40: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

References

• JBoss Seam http://www.seamframework.org

• JBoss Community http://www.jboss.org

• Java EE 5 http://java.sun.com/javaee

• EJB 3.0 http://java.sun.com/products/ejb

• JSF http://java.sun.com/javaee/javaserverfaces

• Facelets http://facelets.dev.java.net

• Web Beans http://jcp.org/en/jsr/detail?id=299

Page 41: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

Books

Page 42: Introduction to JBoss Seam - XeNoNSoFT.com to JBoss Seam ... • Java EE 5 Programming Model • Java Server Faces ... • Unify the 2 main Component models in Java EE 5, EJB 3.0 &

Thank you !