Archive for July 2008

JBoss have released version 4.2.3.GA of their JBoss Application Server.

This is the 3rd bug fixing release of the JBoss Application Server v4.2 series. The aim of this release is to provide fixes for bugs reported by the community against previous JBossAS v4.2.x releases. There were some backwards compatible component upgrades so switching to AS 4.2.3.GA from a previous 4.2.0/4.2.1/4.2.2 release should not present any problems.

For further details, please have a look at the detailed release notes at this location

Download it from here

Before introducing JBoss SEAM Framework, I would like to put some background into perspective first.

Most Java Developers are aware of Model-View-Controller (MVC) frameworks such as Struts and more recently JavaServer Faces or JSF. JSF + Java Persistence API (JPA) combination have a lot of advantages over Struts + EJB 2 combination. These are as follows:

Fewer, finer grained artifacts

  • No Data Transfer Objects (DTOs) required
  • Clean MVC

Less noise

  • No Struts/EJB 2.x boilerplate code
  • No direct calls to HttpSession or HttpRequest

Simple Object-Relational Mapping (ORM)

  • Even simpler than the Hibernate API!

JSF is flexible and extensible

  • Custom UI widget suites (open source)
  • Good AJAX support

JPA

  • Powerful object/relational mapping, far beyond EJB 2.x CMP entity beans
  • All components are POJO so easily testable with TestNG or JUnit

Some disadvantages of using plain JSF are:

JSF

  • Backing bean couples layers and is just noise
  • Hard to refactor all the XML and String outcomes
  • No support for the business layer
  • Validation breaks DRY
  • XML is too verbose

How do we write our business layer

  • EJB3? – Unfortunately it can’t be used directly by JSF
  • EJB3? – It has no concept of scopes

And then there are some more challenges which are:

Workflow

  • Ad-hoc back buttoning not suppored
  • No stateful navigation
  • No support for long running business processes

Multi-tab/window support is not built in

  • All operations happen in the session – so there is memory leakage
  • No support for a conversation context – so wizards have to use Session Scoped objects
  • Memory leak – objects don’t get cleaned up quickly

However, JSF does provide certain advantages which are:

JSF

  • Validation code in the front-end – for example, required=”true” for input fields.
  • Provides converters for Dates, Amounts, etc.
  • Allows calling Business Layer functions directly.
  • Provides a way for outputting messages alongwith severity (error, info, etc.)

Let us now talk about what SEAM brings to the table.

SEAM allows us to Begin and End a conversation – State is maintained over multiple requests
between Begin and End.

For example:


@Name("itemEditor")
@Scope(CONVERSATION)
public class EditItemBean implements EditItem {

@In EntityManager entityManager;
Long id;
Item item;

// getter and setter pairs
@Begin public String find(Long id) {
item = entityManager.find(Item.class, id);
return item == null ? "notFound" : "success";
}

@End public String save(Item item) {
item = entityManager.merge(item);
return "success";
}

}

Following Scopes are available when we make use of SEAM:

Event – Same as Http Request Scope
Page – New to SEAM – Used just for rendering output
Conversation – New to SEAM – Spans several requests
Session
Application
Business Process – New to SEAM – Spans several conversations and even survives Server restart

As you can see, SEAM makes a few new Scopes available to us which are Page, Conversation and Business Process.

How does SEAM store the state information? Well, that depends upon the context we are talking about.

In Page context, the state information is stored in the component tree of the JSF view (page). It can also be stored in HttpSession or serialized to client.

For conversation context, SEAM stores the state information in a Segmented HttpSession. This information times out if not used thus, preventing Memory Leaks.

In Business Process context, the state information is Persisted to database, and is handled by jBPM.

What is Bijection?

Unlike Spring Framework, which only allows Dependency Injection, SEAM allows Dependency Bijection.


@Name("passwordChanger")
public class PasswordChanger {

@In EntityManager entityManager;
@In @Out User currentUser;

public void changePassword() {
entityManager.merge(currentUser);
}

}

In the above example, entityManager is being Injected whereas, currentUser is both injected as well as outjected.

As a result, currentUser’s value will be first made available to changePassword() and then, once it is done, the objected will be made available to whoever needs it.

Scope of currentUser itself will be governed by the scope of the User class.

A brief explanation about JPA Persistence Context

What is the Persistence Context (PC)?

  • It is a HashMap of all the objects I’ve loaded and stored
  • It holds (at most) one in-memory object for each database row while the PC is active
  • It is a natural first-level cache
  • It can do dirty checking of objects and write SQL as late as possible (automatic or manual flushing)

The Persistence Context has a flexible scope

  • default: same scope as the system transaction (JTA)
  • extended: the PC is bound to a stateful session bean

Which PC scope to use in JPA?

Transaction scoped & detached objects

  • LazyInitializationException
  • NonUniqueObjectException
  • Less opportunity for caching

An extended persistence context of a SFSB is

  • not available during view rendering (LIE again)
  • very complicated propagation rules

PC has no concept of a conversation

Advantage of SEAM managed persistence and transactions

  • SEAM managed PC is conversation scoped.
  • It remains active through conversation,
  • It is injected using @In – @In EntityManager entityManager
  • It allows use of manual flush mode

What else does SEAM give us?

  • Security – This can be configured to work at Page, Field, Class, Method or custom level.
  • Email templates
  • PDF templates
  • JavaScript Remoting
  • Asynchronicity (Java SE, EJB3 or Quartz)
  • Provide Google-style search in your app using Hibernate Search
  • Integration and Unit Testing
  • JSF components (deep integration into JPA)
  • Support for RichFaces, ICEFaces and Adobe Flex 3 RIA
  • Components in groovy
  • WebServices
  • More than 25 examples
  • Portal support
  • Validation
  • BPM support
  • Stateful navigation

SEAM 2.1 Roadmap – The near future

  • Providing Wicket as a view layer
  • Providing GWT as a view layer
  • First class support for other other containers (e.g. Websphere)
  • Identity Management
  • Single-Sign-On for security
  • Deeper integration with JBoss Portal (inter-portlet communication)