JBoss Seam is a Java EE-based framework that provides a uniform component model for all the business logic in a Web application and integration between the presentation and the business logic layers. JBoss Seam provides fine-grained state management with its new state contexts. Seam introduces the conversation context, which spans across multiple requests, making it feasible for a user to carry on multiple conversations concurrently, a conversation being a unit of user interaction with an application. The HTTP Session also preserves state across requests, but the state from multiple interactions with an application is not isolated; conversations are not demarcated, and no conversation context is provided. JBoss Seam provides the business process context for long-running business processes consisting of multiple interactions with multiple users. In this tutorial, we shall create a JBoss Seam Model View Controller (MVC) application consisting of an EJB 3.0 entity bean, a stateful session bean, and a JSF user interface.
This tutorial has the following sections.
- Setting the Environment
- Creating a JBoss Seam Web Project
- Creating the JBoss Seam Deployment Structure
Setting the Environment
We need to install the following software:
- JBoss Application Server 7
- MySQL 5.6 Database (Community Edition)
- Eclipse IDE for Java EE Developers
- JBoss Tools (installed as a plug-in to Eclipse
- Apache Maven (version 3.4 or later)
- Java 7
Set the environment variables JAVA_HOME, JBOSS_HOME, MAVEN_HOME, and MYSQL_HOME. Add %JAVA_HOME%/bin, %MAVEN_HOME%/bin, %JBOSS_HOME%/bin and %, and MYSQL_HOME to the PATH environment variable.
Creating a JBoss Seam Web Project
In this section, we shall create a Seam Web project. Select File|New. In New, select Seam|Seam Web Project. Click Next.
Figure 1: Selecting a new project
The New Seam Project wizard gets started. Specify a Project name (catalog), select Target runtime as JBoss 7.1 Runtime, and select Dynamic web module version as 2.5. Click Next.
Figure 2: Selecting catalog
Configure the Java settings; select Source folders on build path as src and the Default output folder as build/classes. Click Next.
Figure 3: Configuring the Java settings
For the Web Module settings, specify Context root as catalog, and Content directory as WebContent. Select Generate web.xml deployment descriptor and click Next.
Figure 4: Configuring the Web Module settings
For JSF Capabilities, select JSF Implementation Library as Library Provided by Target Runtime. Select Configure JSF servlet in the deployment descriptor. Select the default settings for JSF Configuration File (/WEB-INF/faces-config.xml), JSF Servlet Name (Faces Servlet), JSF Servlet Class Name (javax.faces.webapp.FacesServlet), and URL Mapping Patterns (*.seam).
Figure 5: Selecting the JSF Implementation Library
Next, configure the Seam Facet. Select Deploy as EAR. To add a Seam Runtime, click Add. In Home Folder, select the folder in which the JBoss Seam 2.2.0 is installed. Specify a Name (jboss-seam-2.2.0) and click Finish.
Figure 6: Configuring the Seam Facet
The Seam runtime gets configured. The EJB project name and the EAR project name get specified. In Libraries, select Copy Libraries from Seam Runtime. Select Database Type as MySQL 5(InnoDB). To create a new Connection profile, click New.
Figure 7: Configuring the Seam runtime
Select Connection Profile Type as MySQL and specify Name (MySQLConnection). Click Next.
Figure 8: Selecting the Connection Profile Type
Next, specify the driver and connection details. Select the MySQL JDBC Driver. In Properties, specify Database as test, URL as jdbc:mysql://localhost:3306/test, Username as root, and the Password. Click Test Connection to test the connection. If the message Ping succeeded gets displayed, click Next.
Figure 9: Specifying the driver and connection details
In Summary, click Finish.
Figure 10: Clicking Finish
The new Connection Profile gets added. Click Finish.
Figure 11: The Connection Profile is added
The Seam facet gets installed.
Figure 12: The Seam facet is installed
This project is associated with a Seam Perspective. A Seam Web Project, catalog, gets created as shown in the Package Explorer.
Figure 13: Associating the project with a Seam Perspective
We won't be using the default Seam project. Delete all the files and directories from the project root folder catalog. Add the sample Seam project for this tutorial to the catalog folder. Select File|Refresh to add the sample Seam project to the Package Explorer.
Figure 14: Deleting files and directories from the catalog project root folder
Next, we shall discuss each of the sub-projects catalog-ear, catalog-ejb, and catalog-web.
Creating the JBoss Seam Deployment Structure
Classloading in JBoss AS 7 is based on modules, with each module providing some class packages. Classes in one module are not available in another module. Some module dependencies are added by default to a JBoss application based on its requirements; for example, the Hibernate JPA API module is made available in a EJB 3.0 JPA application. The module dependencies added by default are the implicit module dependencies. The \catalog\catalog-ear\src\main\application\META-INF\jboss-deployment-structure.xml file may be used for fine-grained class loading, such as add additional module dependencies or excluding some implicit module dependencies. Because we are using JSF 2.0, we need to exclude the JSF 1.2 modules and add the JSF 2.0 modules. Also, add the org.dom4j module. The jboss-deployment-structure.xml file is listed below.
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0"> <ear-subdeployments-isolated>false</ear-subdeployments-isolated> <deployment> <exclusions> <module name="javax.faces.api" slot="1.2"/> <module name="com.sun.jsf-impl" slot="1.2"/> <module name="org.jboss.integration.ext-content" slot="main"/> </exclusions> <dependencies> <module name="javax.faces.api" slot="main" export="true"/> <module name="com.sun.jsf-impl" slot="main" export="true"/> <module name="org.dom4j" export="true"/> </dependencies> </deployment> </jboss-deployment-structure>
The jboss-deployment-structure.xml file is shown in the Project Explorer.
Figure 15: The jboss-deployment-structure.xml file
We also need to create a MySQL datasource with JNDI MySQLDS. In the next article, we shall discuss creating an entity bean and a session bean façade.