Seam in Action Javapolis University Day 1

Seam is the newest JSF based framework in town and this presentation by Peter Hilton and Pete Muir explained the shortcomings of existing JSF frameworks and ways to overcome these problems with Seam.

Seam promises tight integration with other frameworks/specs including:

  • EJB
  • Hibernate
  • jBPM (java business process management)
  • Richfaces
  • Drools (rules engine)

It also offers Eclipse IDE support with the JBoss tools plugin.

The talk started with an overview of the EJB and JSF enterprise standards:

  • JSF, an event driven, component orientated framework
  • EJB3, a programming model for transactional components:
    • POJOs with annotations
    • Beans which can be stateless, stateful or message driven
    • Dependency injection functionality
    • Declarative handling of transactions and security
    • Object/relational mapping with JPA

Integrating these two technologies we can see the following problems:

JSF problems:

  • the backing bean couples layers and is just noise
  • hard to refactor all the xml and string outcomes in your faces-config.xml/ managed beans
  • no support for the business layer, as you have to integrate BPM, a rule engine, … by yourself
  • validation of input fields is put on the UI, but actually it should be on the model

EJB problems:

  • EJBs can’t be used directly as JSF backing beans
  • EJBs don’t have a context of scopes (session, request, …)

Other problems that can appear:

  • work flow management (eg. back button not supported)
  • no statefull navigation (eg. implementing a wizard accross multiple pages)
  • long running business processes (eg. duration of a week) is not easy todo
  • multi-tab/window support is not supported as everything is in the session and data might get overwritten as the new tab/window uses the same session. (a conversation context solves this in Seam)

Here are some of the interesting features available in Seam:
EJB IS the backing bean in Seam:

public @Name("itemEditor") @Stateful class EditItemBean implements EditItem {}

The @Name annotation lets you use this EJB in your view via an EL binding. (“itemEditor”). This effectively makes this EJB a Seam component.
The EJB is @Stateful as you want to hold the state when eg. a validation error occurs in the JSF lifecycle. The state is managed by your container in this way.

Begin and end a conversation:

You can begin and end a conversation with the following annotations:

        public Item @Begin find(Long id) {)
        public Item @End save(Long id) {)

This means state is kept between invocations of a find and save method invocation.

Contexts in seam:

Seam supports the following contexts where you can put your data in:

  • event
  • page : slightly longer as request scope (=> as long as you stay on the same page (eg. interesting for ajax calls?))
  • conversation : multi browser windows possible (multiple conversations per browser window but same logged-in user)
  • session
  • business process: much longer lived (can be longer then application context, server restarts, … it is normally persisted in your DB)
  • application

Bijections

With the @In and @Out annotations you can not only inject objects into a bean but also do outjection to the Seam managed context
(called Bijections)

An example usage of this:

        @In @Out private User currrentUser;
  • before a method call that uses currentUser the User could be gotten from PersistenceContext (injected into the bean)
  • after the method call that uses the currentUser object finishes, it can be saved back to a PersistanceContext (outjection)

(Hibernate) validation:

Validation rules can be specified on the model. For this Hibernate validation rules are used eg.: @Length, @Max, @Min, @Email, ….

It’s easy to add your own validation annotations and validation UI components can display the errors on screen.

There is a lot more available on Seam but I’m just getting started looking into it 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.