Seam - Contextual Components

Author: Gavin King, Pete Muir, Norman Richards, Shane Bryzak, Michael Yuan, Mike Youngstrom, Christian Bauer, Jay Balunas, Dan Allen, Max Rydahl Andersen, Emmanuel Bernard, Nicklas Karlsson, Daniel Roth, Matt Drees, Jacob Orshalick, and Marek Novotny. Link to original: http://docs.jboss.com/seam/2.1.1.CR2/reference/en-US/html_single/ (English).
Tags: Java, Seam, Seam Framework Submitted by maratische 20.12.2008. Public material.
Introduction to JBoss Seam Seam is an application framework for Enterprise Java. It is inspired by the following principles: One kind of "stuff" Seam defines a uniform component model for all business logic in your application. A Seam component may be stateful, with the state associated with any one of several well-defined contexts, including the long-running, persistent, business process context and the conversation context, which is preserved across multiple web requests in a user interaction. There is no distinction between presentation tier components and business logic components in Seam. You can layer your application according to whatever architecture you devise, rather than being forced to shoehorn your application logic into an unnatural layering scheme forced upon you by whatever combination of stovepipe frameworks you're using today. Unlike plain Java EE or J2EE components, Seam components may simultaneously access state associated with the web request and state held in transactional resources (without the need to propagate web request state manually via method parameters). You might object that the application layering imposed upon you by the old J2EE platform was a Good Thing. Well, nothing stops you creating an equivalent layered architecture using Seam—the difference is that you get to architect your own application and decide what the layers are and how they work together. Integrate JSF with EJB 3.0 JSF and EJB 3.0 are two of the best new features of Java EE 5. EJB3 is a brand new component model for server side business and persistence logic. Meanwhile, JSF is a great component model for the presentation tier. Unfortunately, neither component model is able to solve all problems in computing by itself. Indeed, JSF and EJB3 work best used together. But the Java EE 5 specification provides no standard way to integrate the two component models. Fortunately, the creators of both models foresaw this situation and provided standard extension points to allow extension and integration with other frameworks. Seam unifies the component models of JSF and EJB3, eliminating glue code, and letting the developer think about the business problem. It is possible to write Seam applications where "everything" is an EJB. This may come as a surprise if you're used to thinking of EJBs as coarse-grained, so-called "heavyweight" objects. However, version 3.0 has completely changed the nature of EJB from the point of view of the developer. An EJB is a fine-grained object—nothing more complex than an annotated JavaBean. Seam even encourages you to use session beans as JSF action listeners! On the other hand, if you prefer not to adopt EJB 3.0 at this time, you don't have to. Virtually any Java class may be a Seam component, and Seam provides all the functionality that you expect from a "lightweight" container, and more, for any component, EJB or otherwise. Integrated AJAX Seam supports the best open source JSF-based AJAX solutions: JBoss RichFaces and ICEfaces. These solutions let you add AJAX capability to your user interface without the need to write any JavaScript code. Alternatively, Seam provides a built-in JavaScript remoting layer that lets you call components asynchronously from client-side JavaScript without the need for an intermediate action layer. You can even subscribe to server-side JMS topics and receive messages via AJAX push. Neither of these approaches would work well, were it not for Seam's built-in concurrency and state management, which ensures that many concurrent fine-grained, asynchronous AJAX requests are handled safely and efficiently on the server side. Business process as a first class construct Optionally, Seam provides transparent business process management via jBPM. You won't believe how easy it is to implement complex workflows, collaboration and and task management using jBPM and Seam. Seam even allows you to define presentation tier pageflow using the same language (jPDL) that jBPM uses for business process definition. JSF provides an incredibly rich event model for the presentation tier. Seam enhances this model by exposing jBPM's business process related events via exactly the same event handling mechanism, providing a uniform event model for Seam's uniform component model. Declarative state management We're all used to the concept of declarative transaction management and declarative security from the early days of EJB. EJB 3.0 even introduces declarative persistence context management. These are three examples of a broader problem of managing state that is associated with a particular context, while ensuring that all needed cleanup occurs when the context ends. Seam takes the concept of declarative state management much further and applies it to application state. Traditionally, J2EE applications implement state management manually, by getting and setting servlet session and request attributes. This approach to state management is the source of many bugs and memory leaks when applications fail to clean up session attributes, or when session data associated with different workflows collides in a multi-window application. Seam has the potential to almost entirely eliminate this class of bugs. Declarative application state management is made possible by the richness of the context model defined by Seam. Seam extends the context model defined by the servlet spec—request, session, application—with two new contexts—conversation and business process—that are more meaningful from the point of view of the business logic. You'll be amazed at how many things become easier once you start using conversations. Have you ever suffered pain dealing with lazy association fetching in an ORM solution like Hibernate or JPA? Seam's conversation-scoped persistence contexts mean you'll rarely have to see a LazyInitializationException. Have you ever had problems with the refresh button? The back button? With duplicate form submission? With propagating messages across a post-then-redirect? Seam's conversation management solves these problems without you even needing to really think about them. They're all symptoms of the broken state management architecture that has been prevalent since the earliest days of the web. Bijection The notion of Inversion of Control or dependency injection exists in both JSF and EJB3, as well as in numerous so-called "lightweight containers". Most of these containers emphasize injection of components that implement stateless services. Even when injection of stateful components is supported (such as in JSF), it is virtually useless for handling application state because the scope of the stateful component cannot be defined with sufficient flexibility, and because components belonging to wider scopes may not be injected into components belonging to narrower scopes. Bijection differs from IoC in that it is dynamic, contextual, and bidirectional. You can think of it as a mechanism for aliasing contextual variables (names in the various contexts bound to the current thread) to attributes of the component. Bijection allows auto-assembly of stateful components by the container. It even allows a component to safely and easily manipulate the value of a context variable, just by assigning it to an attribute of the component. Workspace management and multi-window browsing Seam applications let the user freely switch between multiple browser tabs, each associated with a different, safely isolated, conversation. Applications may even take advantage of workspace management, allowing the user to switch between conversations (workspaces) in a single browser tab. Seam provides not only correct multi-window operation, but also multi-window-like operation in a single window! Prefer annotations to XML Traditionally, the Java community has been in a state of deep confusion about precisely what kinds of meta-information counts as configuration. J2EE and popular "lightweight" containers have provided XML-based deployment descriptors both for things which are truly configurable between different deployments of the system, and for any other kinds or declaration which can not easily be expressed in Java. Java 5 annotations changed all this. EJB 3.0 embraces annotations and "configuration by exception" as the easiest way to provide information to the container in a declarative form. Unfortunately, JSF is still heavily dependent on verbose XML configuration files. Seam extends the annotations provided by EJB 3.0 with a set of annotations for declarative state management and declarative context demarcation. This lets you eliminate the noisy JSF managed bean declarations and reduce the required XML to just that information which truly belongs in XML (the JSF navigation rules). Integration testing is easy Seam components, being plain Java classes, are by nature unit testable. But for complex applications, unit testing alone is insufficient. Integration testing has traditionally been a messy and difficult task for Java web applications. Therefore, Seam provides for testability of Seam applications as a core feature of the framework. You can easily write JUnit or TestNG tests that reproduce a whole interaction with a user, exercising all components of the system apart from the view (the JSP or Facelets page). You can run these tests directly inside your IDE, where Seam will automatically deploy EJB components using JBoss Embedded. The specs ain't perfect We think the latest incarnation of Java EE is great. But we know it's never going to be perfect. Where there are holes in the specifications (for example, limitations in the JSF lifecycle for GET requests), Seam fixes them. And the authors of Seam are working with the JCP expert groups to make sure those fixes make their way back into the next revision of the standards. There's more to a web application than serving HTML pages Today's web frameworks think too small. They let you get user input off a form and into your Java objects. And then they leave you hanging. A truly complete web application framework should address problems like persistence, concurrency, asynchronicity, state management, security, email, messaging, PDF and chart generation, workflow, wikitext rendering, webservices, caching and more. Once you scratch the surface of Seam, you'll be amazed at how many problems become simpler... Seam integrates JPA and Hibernate3 for persistence, the EJB Timer Service and Quartz for lightweight asychronicity, jBPM for workflow, JBoss Rules for business rules, Meldware Mail for email, Hibernate Search and Lucene for full text search, JMS for messaging and JBoss Cache for page fragment caching. Seam layers an innovative rule-based security framework over JAAS and JBoss Rules. There's even JSF tag libraries for rendering PDF, outgoing email, charts and wikitext. Seam components may be called synchronously as a Web Service, asynchronously from client-side JavaScript or Google Web Toolkit or, of course, directly from JSF. Get started now! Seam works in any Java EE application server, and even works in Tomcat. If your environment supports EJB 3.0, great! If it doesn't, no problem, you can use Seam's built-in transaction management with JPA or Hibernate3 for persistence. Or, you can deploy JBoss Embedded in Tomcat, and get full support for EJB 3.0. [Image] It turns out that the combination of Seam, JSF and EJB3 is the simplest way to write a complex web application in Java. You won't believe how little code is required!

Translations of this material:

into Russian: Seam - Контекстуальные Компоненты. 5% translated in draft.
Submitted for translation by maratische 20.12.2008 Published 2 years, 3 months ago.

Text

SeamFramework.orgCommunity Documentation
Seam - Contextual Components
A Framework for Enterprise Java
by Gavin King, Pete Muir, Norman Richards, Shane Bryzak, Michael Yuan, Mike Youngstrom, Christian Bauer, Jay Balunas, Dan Allen, Max Rydahl Andersen, Emmanuel Bernard, Nicklas Karlsson, Daniel Roth, Matt Drees, Jacob Orshalick, and Marek Novotny
edited by Samson Kittoli
and thanks to James Cobb (Graphic Design), Cheyenne Weaver (Graphic Design), Mark Newton, Steve Ebersole, and Michael Courcy (French Translation)

2.1.1.CR2

Introduction to JBoss Seam

1. Contribute to Seam

1. Seam Tutorial

1.1. Using the Seam examples

1.1.1. Running the examples on JBoss AS
1.1.2. Running the examples on Tomcat
1.1.3. Running the example tests

1.2. Your first Seam application: the registration example

1.2.1. Understanding the code
1.2.2. How it works

1.3. Clickable lists in Seam: the messages example

1.3.1. Understanding the code
1.3.2. How it works

1.4. Seam and jBPM: the todo list example

1.4.1. Understanding the code
1.4.2. How it works

1.5. Seam pageflow: the numberguess example

1.5.1. Understanding the code
1.5.2. How it works

1.6. A complete Seam application: the Hotel Booking example

1.6.1. Introduction
1.6.2. Overview of the booking example
1.6.3. Understanding Seam conversations
1.6.4. The Seam Debug Page

1.7. Nested conversations: extending the Hotel Booking example

1.7.1. Introduction
1.7.2. Understanding Nested Conversations

1.8. A complete application featuring Seam and jBPM: the DVD Store example
1.9. Bookmarkable URLs with the Blog example

1.9.1. Using "pull"-style MVC
1.9.2. Bookmarkable search results page
1.9.3. Using "push"-style MVC in a RESTful application

2. Getting started with Seam, using seam-gen

2.1. Before you start
2.2. Setting up a new Eclipse project
2.3. Creating a new action
2.4. Creating a form with an action
2.5. Generating an application from an existing database
2.6. Generating an application from existing JPA/EJB3 entities
2.7. Deploying the application as an EAR
2.8. Seam and incremental hot deployment
2.9. Using Seam with JBoss 4.0

2.9.1. Install JBoss 4.0
2.9.2. Install the JSF 1.2 RI

3. Getting started with Seam, using JBoss Tools

3.1. Before you start
3.2. Setting up a new Seam project
3.3. Creating a new action
3.4. Creating a form with an action
3.5. Generating an application from an existing database
3.6. Seam and incremental hot deployment with JBoss Tools

4. The contextual component model

4.1. Seam contexts

4.1.1. Stateless context
4.1.2. Event context
4.1.3. Page context
4.1.4. Conversation context
4.1.5. Session context
4.1.6. Business process context
4.1.7. Application context
4.1.8. Context variables
4.1.9. Context search priority
4.1.10. Concurrency model

4.2. Seam components

4.2.1. Stateless session beans
4.2.2. Stateful session beans
4.2.3. Entity beans
4.2.4. JavaBeans
4.2.5. Message-driven beans
4.2.6. Interception
4.2.7. Component names
4.2.8. Defining the component scope
4.2.9. Components with multiple roles
4.2.10. Built-in components

4.3. Bijection
4.4. Lifecycle methods
4.5. Conditional installation
4.6. Logging
4.7. The Mutable interface and @ReadOnly
4.8. Factory and manager components

5. Configuring Seam components

5.1. Configuring components via property settings
5.2. Configuring components via components.xml
5.3. Fine-grained configuration files
5.4. Configurable property types
5.5. Using XML Namespaces

6. Events, interceptors and exception handling

6.1. Seam events
6.2. Page actions
6.3. Page parameters

6.3.1. Mapping request parameters to the model

6.4. Propagating request parameters
6.5. URL rewriting with page parameters
6.6. Conversion and Validation
6.7. Navigation
6.8. Fine-grained files for definition of navigation, page actions and parameters
6.9. Component-driven events
6.10. Contextual events
6.11. Seam interceptors
6.12. Managing exceptions

6.12.1. Exceptions and transactions
6.12.2. Enabling Seam exception handling
6.12.3. Using annotations for exception handling
6.12.4. Using XML for exception handling
6.12.5. Some common exceptions

6.13. conversation-required

7. Conversations and workspace management

7.1. Seam's conversation model
7.2. Nested conversations
7.3. Starting conversations with GET requests
7.4. Using <s:link> and <s:button>
7.5. Success messages
7.6. Natural conversation ids
7.7. Creating a natural conversation
7.8. Redirecting to a natural conversation
7.9. Workspace management

7.9.1. Workspace management and JSF navigation
7.9.2. Workspace management and jPDL pageflow
7.9.3. The conversation switcher
7.9.4. The conversation list
7.9.5. Breadcrumbs

7.10. Conversational components and JSF component bindings
7.11. Concurrent calls to conversational components

7.11.1. How should we design our conversational AJAX application?
7.11.2. Dealing with errors
7.11.3. RichFaces Ajax

8. Pageflows and business processes

8.1. Pageflow in Seam

8.1.1. The two navigation models
8.1.2. Seam and the back button

8.2. Using jPDL pageflows

8.2.1. Installing pageflows
8.2.2. Starting pageflows
8.2.3. Page nodes and transitions
8.2.4. Controlling the flow
8.2.5. Ending the flow
8.2.6. Pageflow composition

8.3. Business process management in Seam
8.4. Using jPDL business process definitions

8.4.1. Installing process definitions
8.4.2. Initializing actor ids
8.4.3. Initiating a business process
8.4.4. Task assignment
8.4.5. Task lists
8.4.6. Performing a task

9. Seam and Object/Relational Mapping

9.1. Introduction
9.2. Seam managed transactions

9.2.1. Disabling Seam-managed transactions
9.2.2. Configuring a Seam transaction manager
9.2.3. Transaction synchronization

9.3. Seam-managed persistence contexts

9.3.1. Using a Seam-managed persistence context with JPA
9.3.2. Using a Seam-managed Hibernate session
9.3.3. Seam-managed persistence contexts and atomic conversations

9.4. Using the JPA "delegate"
9.5. Using EL in EJB-QL/HQL
9.6. Using Hibernate filters

10. JSF form validation in Seam
11. Groovy integration

11.1. Groovy introduction
11.2. Writing Seam applications in Groovy

11.2.1. Writing Groovy components
11.2.2. seam-gen

11.3. Deployment

11.3.1. Deploying Groovy code
11.3.2. Native .groovy file deployment at development time
11.3.3. seam-gen

12. Writing your presentation layer using Apache Wicket

12.1. Adding Seam to your wicket application

12.1.1. Bijection
12.1.2. Orchestration

12.2. Setting up your project

12.2.1. Defining the Application

13. The Seam Application Framework

13.1. Introduction
13.2. Home objects
13.3. Query objects
13.4. Controller objects

14. Seam and JBoss Rules

14.1. Installing rules
14.2. Using rules from a Seam component
14.3. Using rules from a jBPM process definition

15. Security

15.1. Overview
15.2. Disabling Security
15.3. Authentication

15.3.1. Configuring an Authenticator component
15.3.2. Writing an authentication method
15.3.3. Writing a login form
15.3.4. Configuration Summary
15.3.5. Remember Me
15.3.6. Handling Security Exceptions
15.3.7. Login Redirection
15.3.8. HTTP Authentication
15.3.9. Advanced Authentication Features

15.4. Identity Management

15.4.1. Configuring IdentityManager
15.4.2. JpaIdentityStore
15.4.3. LdapIdentityStore
15.4.4. Writing your own IdentityStore
15.4.5. Authentication with Identity Management
15.4.6. Using IdentityManager

15.5. Error Messages
15.6. Authorization

15.6.1. Core concepts
15.6.2. Securing components
15.6.3. Security in the user interface
15.6.4. Securing pages
15.6.5. Securing Entities
15.6.6. Typesafe Permission Annotations
15.6.7. Typesafe Role Annotations
15.6.8. The Permission Authorization Model
15.6.9. RuleBasedPermissionResolver
15.6.10. PersistentPermissionResolver

15.7. Permission Management

15.7.1. PermissionManager
15.7.2. Permission checks for PermissionManager operations

15.8. SSL Security

15.8.1. Overriding the default ports

15.9. CAPTCHA

15.9.1. Configuring the CAPTCHA Servlet
15.9.2. Adding a CAPTCHA to a form
15.9.3. Customising the CAPTCHA algorithm

15.10. Security Events
15.11. Run As
15.12. Extending the Identity component
15.13. OpenID

15.13.1. Configuring OpenID
15.13.2. Presenting an OpenIdDLogin form
15.13.3. Logging in immediately
15.13.4. Deferring login
15.13.5. Logging out

16. Internationalization, localization and themes

16.1. Internationalizing your app

16.1.1. Application server configuration
16.1.2. Translated application strings
16.1.3. Other encoding settings

16.2. Locales
16.3. Labels

16.3.1. Defining labels
16.3.2. Displaying labels
16.3.3. Faces messages

16.4. Timezones
16.5. Themes
16.6. Persisting locale and theme preferences via cookies

17. Seam Text

17.1. Basic fomatting
17.2. Entering code and text with special characters
17.3. Links
17.4. Entering HTML

18. iText PDF generation

18.1. Using PDF Support

18.1.1. Creating a document
18.1.2. Basic Text Elements
18.1.3. Headers and Footers
18.1.4. Chapters and Sections
18.1.5. Lists
18.1.6. Tables
18.1.7. Document Constants

18.2. Charting
18.3. Bar codes
18.4. Fill-in-forms
18.5. Rendering Swing/AWT components
18.6. Configuring iText
18.7. Further documentation

19. The Microsoft® Excel® spreadsheet application

Pages: ← previous Ctrl next

© jboss.org.