faisal has posted 2 posts at DZone. View Full User Profile

Magic of JBoss Seam

04.16.2009
| 11648 views |
  • submit to reddit

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:

@Entity
@Name("xyz")
@Scope(SESSION)
@Table(name="tablename")
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:


@Stateless
@Name("abc")
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:

<lifecycle>
<phase-listener>org.jboss.seam.jsf.SeamPhaseListener</phase-listener>
</lifecycle>

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.):
#{abc.methodX}

 

Published at DZone with permission of its author, faisal khan.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Stephen Strenn replied on Thu, 2009/04/16 - 11:46am

Where is the rest of the article. This is really light.  You should probably have a simple, clear example (including logic and view) that highlights just how easy Seam makes it to implement.

Dan Allen replied on Mon, 2009/04/20 - 9:31pm

I'm very disappointed that this article was published on DZone. It has little useful information. It's probably best to just ignore this article and look for something that is more complete. There are plenty of articles available. If you can't seem to find one right away, I've catagorized a whole bunch of them for you here: http://delicious.com/seaminaction.

faisal khan replied on Fri, 2009/04/24 - 3:50pm in response to: Dan Allen

Sorry to dissapoint you so much:) , but the article above focuses exactly on how to use seam in your applications( without any of the architectural documentations,which are present all over the net), I wrote it from a developer's point of view, its really important for a newbie to create a small example before he gets on with the bigger stuff for any technology , this also tells about how to move from EJB2 to EJB3, I am a developer and not a professor to brag about the documentation, all I focussed was on the way of implementation. thanks anyways.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.