Over a million developers have joined DZone.

Magic of JBoss Seam

DZone's Guide to

Magic of JBoss Seam

· Java Zone
Free Resource

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's free.

The new features of JavaEE 5, JSF and EJB3 work great together, and Seam is an application framework which does it easily. It introduces us to two new additions to default contexts of components, which are the long running business process context and the conversation context, which is preserved during multiple user requests. Here I will concentrate on how the things have changed from EJB2 and on better integration of JSF and EJB3.

Seam does it using annotations. We'll start by defining an Enity. I will discuss only prominent annotations:

public class EntityClass{ ....... }


  1. The @Entity annotation indicates that the class in an entity bean.
  2. @Name is the Seam component name of this class. This name can be used anywhere to denote this class .This name should be unique within the Seam application.
  3. The @Scope annotation denotes the scope of the Seam component. Everytime Seam instantiates a component it will bind it to the default context.
  4. @Table indicates that the EntityClass is mapped to "tablename" table.

Now we will see how Stateless Session Beans are defined using Seam. It's very simple - all we have to do is use the @Stateless as shown below:

public class sessionBeanClass{ ..... }

where @Name again denotes the name of the Seam component

Note that we did not define the @Scope - that's because the default Seam scope for Stateless Session Beans is the stateless context.

Finally, to define the session bean Local interface, we denoting the class with the @Local annotation.

@Local @Name("interface" public class LocalInterface{ .... }

We have to make an entry in faces-config.xml as follows:


You can see how Seam makes it really easy to glue our presentation with the business logic, 
as now we can use the Seam name of the components directly to denote the classes anywhere
in the Seam application.
Suppose a method methodX() in the component SessionBeanClass could be invoked by the following expression in the view(jsp,xhtml, etc.):


Bitbucket is the Git solution for professional teams who code with a purpose, not just as a hobby. Get started today, it's free.


Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}