Understanding JBoss Seam Registration example
What is JBoss Seam?
- It is Framework that integrates JSF, EJB 3/POJO and JPA very well. JSF is a component technology that allows developers to reuse components. There are many JSF component providers, such as Rich faces and Ice faces. Java Persistence API (JPA) is java standard for mapping java object to a relational database.
- Seam is also a context based dependency injection framework. Seam allows developers to inject Seam container managed object into Seam component. Seam container is responsible for creating and managing the life cycle of the object. Dependency injection framework promotes loose coupling design pattern. The client of a java object is not responsible for the creating of the object. Therefore, the client is not dependent on the implementation of the java object.
- Seam enhanced JSF. It provides a whole solution to an entire web application project. For example, it provides many extra features such as scheduler and email integration.
The Registration example
JBoss Seam distribution comes with many sample applications. The registration example allows users to store his username, real name and password in the database. Blow is a screen shoot from Seam Document.
The Entity bean: user.java
- Entity annotation indicates that the user class is an entity
- Name annotation indicates that the user class is a JBoss seam component named “user”
- Scope annotation indicates that the context associated with the class
- NotNull annotation is part of the Hibernate validator framework that can be used in persistent layer and JSF layer
The Action class: RegisterAction.java
- Stateless annotation indicates that the Registration class is a stateless session bean
- In annotation indicates that user object will be injected by Seam container
- PersistenceContext annotation indicates that the EntityManager object em will be injected.
- The register method simply uses entity manager to persist the user object into database.
The View: Register.xhtml
- S:validateAll tag tell Seam to validate all input fields against Hibernate validator
- JSF facelet EL “#user.username” binds the username input field to the username attribute of the “user” Seam component.
- The commandButton tag binds the “register” button to the “register” method of “register” component. When a user clicks on the register button, the register method will be invoked.
The View: Registered.xhtml
- When the register method is successfully executed, the system will then display the registered message.
registered.bmp 712.6 KB