Seam Overview

The Basics

Links and tips about JBoss SEAM.

Understanding Seam Contexts

See Understanding Seam Contexts

Cool Stuff that Seam Does

Well, Seam does a whole lot of cool stuff. Here are the things that I thought were important.

Conversations, EJB Extended Persistence Contexts and Transactions

In EJB3 a persistence context (managed entities in an EntityManager) can extend beyond transaction boundaries when used inside a stateful EJB, comitting only when needed. This persistence context forms a convenient 'cache' of all the objects in the unit of work (from the user's perspective). This allows Web/EJB3 applications to completely avoid the constant re-loading of entities on every single web request-response cycle. What Seam does is integrate this nearly transparently into the JSF layer by allowing stateful EJBs to be managed in a Seam context scope, the most interesting scope being conversation scope.

Seam also provides built in components for switching and cancelling long running conversations. This is a huge win over designing this kind of thing yourself.

  • Users can leave activities partially finished and return to them later or cancel them.
  • Developers can build user interfaces to allow users to do this kind of thing with zero Java code . Just access the built in components in the view.

Seam works with Ajax4JSF

Seam can be used with the Ajax4JSF UI components in order to make the web UI more.

Seam Application Framework

Write less code! The Seam application framework provides built in components that allow you to pretty much just write the entity and the view. The framework takes care of doing all the business logic class.

http://docs.jboss.com/seam/latest/reference/en/html/framework.html

Security with Seam

Extended JSF/EL

You can call methods in JSF/EL, and even pass parameters!

Seam UI components

See http://docs.jboss.com/seam/latest/reference/en/html/controls.html

The most useful are:

  • <s:div> - Ever want to make a div that has the rendered="..." attribute? Well here it is.

Seam Security

Even with the 'simple' security mode Seam provides a very powerful and flexible way to implement security.

  • You can use EL expressions in the @Restrict annotation to reference your own security checking components.
  • You can use the same EL expressions in the <restrict> element in pages.xml to use your own security checking components on pages.
  • Seam comes with built in 'redirect after login' features (i.e. go to the URL the user typed in after logging in).
  • Update: Seam 2.1.0 has more "identity management" features including ACL security.

Unit Testing

One of the weakest points in developing web / J2EE applications is that they can be cumbersome to test. Seam provides a built in unit test framework based on [MWI:TestNG] that can simulate JSF lifecycles and interpret EL expressions. Unit tests can be run using the Embedded EJB3 container or Embedded JBoss so you can test everything about the application except the view code.

Transitioning to EJB3/Seam

There are a few things that one needs to unlearn when moving from EJB2.x and something like Struts/JSP to the world of EJB3/Seam.

EJBs as JSF Backing Beans

In Seam you can directly connect the JSF view to EJBs, and you can do it without any XML artifacts. This may seem a bit odd at first, but even if you only use this part of Seam in your application it will significantly reduce the amount of code artifacts you need to make to build a feature.

Here is a simple comparison of the code artifacts required for a basic JSF application:

Vanilla JSF Seam and JSF
  • inputText widgets are bound to properties of a backing bean
  • commandButtons and commandLinks are bound to methods of a backing bean
  • The action method in the backing bean looks up an EJB the usual way and then invokes the business logic though the business interface.
    Artifacts required:
  • Entity and session bean
  • View
  • Backing beans - 'form' backing beans and 'controller' backing beans are POJOS
  • JSF backing bean configuration - POJO backing beans are registered in a JSF configuration file
  • commandButtons and commandLinks are bound to EJB methods.
  • action methods in EJBs can outject entities into the contexts for by inputText widgets on the next page.
  • inputText widgets can be bound directly to entity properties.

Seam removes the need for:

  • Separate POJO backing beans - 'form' backing beans can be entities, and the 'controller' can be the a SFSB or SLSB. Intermediate form and controller POJOS are not needed.
  • JSF backing bean configuration - The @Name annotation is all that is needed to register Java classes with JSF.

The Seam Interceptor and Stateless Session EJBs

In an EJB2.x application it is not uncommon to have stateless session EJBs that have fields which refer to other stateless components, for example other stateless EJBs or DAOs. With Seam, it is common to make use of fields that are bound to technically stateful objects, for example entities that are in the conversation context. Now, you might ask: "How can a stateless session EJB have fields that are not also stateless?". Good question. The answer is in the way the Seam interceptor handles the contexts.

The Seam interceptor will inject values from the context into the stateless session EJB, invoke the EJB method, then outject any values back into the context. Remember, the context in this case is actually the whole stack of contexts including the conversation context. This allows the 'stateless' EJB object to borrow state from the contexts while it is executing, thereby giving the stateless session EJB pseudo-stateful behavior.

When a stateless EJB is accessed concurrently, the EJB container will provide a pool of stateless session bean instances. The Seam interceptor simply injects the context values into the instance being used for each call.

Things to remember about using fields in statless session EJBs with Seam:

  • Fields must be either references to other stateless objects, or seam-injected values.
  • References to other stateless session EJBs can be made with the @EJB annotation.
  • Fields that are seam-injected with the @In annotation will be 'borrowed' from the contexts every time a method on the bean is invoked.
  • Fields that are not injected via @EJB or @In must be completely stateless and have no mutators (i.e. no setter methods), as that would result in strange behavior.

Seam Troubleshooting

See Seam Troubleshooting

Seam Tips And Techniques

Other Seam links

Labels

seam seam Delete
jboss jboss Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.