Chapter 10. The Seam Application Framework
Seam makes it really easy to create applications by writing plain Java classes with annotations, which don't need to extend any special interfaces or superclasses. But we can simplify some common programming tasks even further, by providing a set of pre-built components which can be re-used either by configuration in components.xml
(for very simple cases) or extension.
We should emphasize that the framework is extremely simple, just a handful of simple classes that are easy to understand and extend. The "magic" is in Seam itself—the same magic you use when creating any Seam application even without using this framework.
The components provided by the Seam application framework may be used in one of two different approaches. The first way is to install and configure an instance of the component in components.xml
, just like we have done with other kinds of built-in Seam components. For example, the following fragment from components.xml
installs a component which can perform basic CRUD operations for a Contact
entity:
<framework:entity-home name="personHome"
entity-class="eg.Person"
entity-manager="#{personDatabase}">
<framework:id>#{param.personId}</framework:id>
</framework:entity-home>
If that looks a bit too much like "programming in XML" for your taste, you can use extension instead:
@Stateful
@Name("personHome")
public class PersonHome extends EntityHome<Person> implements LocalPersonHome {
@RequestParameter String personId;
@In EntityManager personDatabase;
public Object getId() { return personId; }
public EntityManager getEntityManager() { return personDatabase; }
}
The second approach has one huge advantage: you can easily add extra functionality, and override the built-in functionality (the framework classes were carefully designed for extension and customization).
A second advantage is that your classes may be EJB stateful sessin beans, if you like. (They do not have to be, they can be plain JavaBean components if you prefer.)
At this time, the Seam Application Framework provides just four built-in components: EntityHome
and HibernateEntityHome
for CRUD, along with EntityQuery
and HibernateEntityQuery
for queries.
The Home and Query components are written so that they can function with a scope of session, event or conversation. Which scope you use depends upon the state model you wish to use in your application.
The Seam Application Framework only works with Seam-managed persistence contexts. By default, the components will look for a persistence context named entityManager
.