Seam Dev Tools Reference Guide

Version: 2.0.0.GA


+1. Introduction
1.1. What is Seam?
1.2. Other relevant resources on the topic
+2. Creating a New Seam Project via the New Seam Project wizard
2.1. Create standalone Seam Web Project
2.2. Select the Project Facets
2.3. How to Configure Web Module Settings
2.4. Adding JSF Capabilities
2.5. Configure Seam Facet Settings
+3. Directory Structure of the Generated Project
3.1. WAR Deployment
3.2. EAR Deployment
+4. Seam Wizards
4.1. New Seam Action
4.2. New Seam Form
4.3. New Seam Conversation
4.4. New Seam Entity
5. Seam Generate Entities
+6. Seam Editors Features
6.1. Content Assist
6.2. OpenOn
6.3. Seam Validation
+7. Seam Views
7.1. Seam Components View
7.2. Project Explorer integration
+8. Generate a CRUD Database Application
8.1. What is CRUD?
8.2. How to create the CRUD Database Application with Seam
+9. The CRUD Application Walkthrough
9.1. Using CRUD Application
+10. Using TestNG project
10.1. What is TestNG?
10.2. Other relevant resources on the topic
10.3. How to use the generated Seam-test project to run Seam tests?

Chapter 1. Introduction

1.1. What is Seam?

Seam is a fully featured application framework on top of Java EE 5. It is also one of the most popular enterprise Java framework today. Seam deeply integrates many other standard-based or open source frameworks (e.g., JSF, EJB3, JMS, Web Services, jBPM, JBoss Rules, Ajax4jsf, RichFaces, Facelets, Spring, iText, Quartz, TestNG, etc.), and provides a single programming model for developers to "drive" those underlying frameworks via simple annotated POJOs (Plain Old Java Objects). It makes life easier for developers to tackle complex enterprise applications with many component frameworks.

1.2. Other relevant resources on the topic

Seam Framework

Chapter 2. Creating a New Seam Project via the New Seam Project wizard

To start working with Seam, select a Seam perspective via Window > Open Perspective > Other > Seam. Select File > New > Seam Web Project to run the New Seam Project wizard.

2.1. Create standalone Seam Web Project

It's necessary to enter a name and a location directory for your new project. The next wizard forms allow you to create runtime and server instances in order to get started creating, running, and debugging J2EE applications.

Seam Web Project wizard has an option for selecting the actual Server (not just WTP runtime) that will be used for the project. This allows the wizard to identify correctly where the required datasource and driver libraries need to go.

New Seam Project Wizard

Figure 2.1. New Seam Project Wizard


Click on New... button in the Target Runtime section.

From this dialog you can choose what type of runtime you want to create. Let's create a JBoss 4.2 Runtime. Click on Next.

New Server Runtime Dialog

Figure 2.2. New Server Runtime Dialog


All what you need here is to name runtime, browse to its install directory, select a Java Runtime Environment, and select which configuration you want. Click on Finish.

New Server Runtime Dialog

Figure 2.3. New Server Runtime Dialog


Now you should define an installed server by clicking on New... button in the Target section. It's possible to select a server version and a server runtime. Use Installed Runtimes button to see or edit what runtimes are installed. Click on Next

New Server Dialog

Figure 2.4. New Server Dialog


Leave everything as is and click on next.

New Server Dialog

Figure 2.5. New Server Dialog


On the last wizard step you can modify your project to configure it on server.

New Server Dialog

Figure 2.6. New Server Dialog


After clicking on Finish button you should have the following wizard view:

New Seam Project Creation

Figure 2.7. New Seam Project Creation


The last section on this wizard step is Configurations. You can select one of the pre-defined project configuration or create your own. Click on Next.

2.2. Select the Project Facets

This page of the wizard allows you to enable or disable specific facets. You can save or delete your preset of selected facets clicking on Save button.

Project Facets Selection

Figure 2.8. Project Facets Selection


You can also see all available runtimes after clicking on Show Runtimes or create new ones using the New button.

Project Facets Selection

Figure 2.9. Project Facets Selection


2.3. How to Configure Web Module Settings

A dynamic web application contains both web pages and Java code. The wizard will ask you where you want to put those files. You can just leave the default values.

Web Module Settings

Figure 2.10. Web Module Settings


2.4. Adding JSF Capabilities

This wizard helps you to add JSF capabilities into your project.

Checking Server Supplied JSF Implementation means that you will have a default JSF implementation given by server.

Adding JSF Capabilities to Web Project

Figure 2.11. Adding JSF Capabilities to Web Project


In case when you want to use your custom JSF implementation check a lower radio button. You are able to create a library of jars by clicking on New button.

Type a Library Name, select a Version Supported and add Library jars. Click on Finish.

Create JSF Implementation Library

Figure 2.12. Create JSF Implementation Library


You can also add a Component Libraries (e.g. Richfaces) clicking on New button in the Component Libraries section.

Create JSF Implementation Library

Figure 2.13. Create JSF Implementation Library


The last wizard options allows to edit a path for JSF Configuration File, a name for JSF Servlet, JSF Servlet Classname and change an URL Mapping Patterns.

JSF Capabilities Wizard

Figure 2.14. JSF Capabilities Wizard


2.5. Configure Seam Facet Settings

The last wizard step is related to Seam facet and allows you to do the following:

Seam Facet Settings

Figure 2.15. Seam Facet Settings


  • Create Seam runtime and define Seam home folder. Click on Add button in the General section.

Notice that in this wizard presented below you can create a Seam runtime only for that version which was selected in the Project Facets wizard (version 1.2 in our case).

Seam Runtime Creation

Figure 2.16. Seam Runtime Creation


  • Select EAR or WAR deployment by checking a necessary radio button.

  • Select a Database Type

Seam Runtime Creation

Figure 2.17. Seam Runtime Creation


  • and create a Connection profile clicking on New button and selecting the necessary connection profile.

Connection Profile Selecting

Figure 2.18. Connection Profile Selecting


Other Database fields are describing a Database and a connection to it.

In the Code Generation section you can edit a package name for Session Bean, Entity Bean and Test.

Code Generation Section

Figure 2.19. Code Generation Section


Click on Finish to generate a project.

Chapter 3. Directory Structure of the Generated Project

In this chapter we describe where the Seam wizard puts the generated files for both EAR and WAR deployments.

The Seam Project wizard generates projects like Eclipse WTP style in order to utilize Eclipse WTP features and to have a correct classpath. To be more precise it generates one project per artifact.

3.1. WAR Deployment

The project layout for WAR projects is:

Project Layout for WAR projects

Figure 3.1. Project Layout for WAR projects


A WAR project can only use Seam JavaBean and JPA Entity bean components; it cannot use EJB3 Session beans etc.

WAR projects are generated to enable Seam 1.2.1 war hotdeploy feature. Classes put into src/action will be deployed to WEB-INF/dev from which Seam 1.2.1 automatically will perform hotdeploy of new components.

Note:

Because of Eclipse WTP limits the hot deployed classes also existed in WEB-INF/classes, but since Seam gives WEB-INF/dev precedence it will work.

Furthermore the Seam Project wizard generates a test project that is setup to run TestNG directly against the proper libraries and server runtime libraries. When the TestNG plugin is installed you can just run your tests via Run As > TestNG Test.

3.2. EAR Deployment

The project layout for EAR projects is:

Project Layout for WAR projects

Figure 3.2. Project Layout for WAR projects


An EAR project can use the whole range of Seam components, including EJB3 Session beans.

Chapter 4. Seam Wizards

All the Seam component generations options known from Seam-gen are available as wizards (with sensible auto-defaulting) for creating various common Seam components:

  • Seam Action

  • Seam Form

  • Seam Entity

  • Seam Conversation

Go to File > New and select the component wizard.

Seam Component Wizards

Figure 4.1. Seam Component Wizards


The wizards create multiple resources and place it in the appropriate folders depending on your project structure (WAR or EAR).

Let's create a WAR project using the New Seam Project wizard.

Seam Project WAR Deployment

Figure 4.2. Seam Project WAR Deployment


After the project is created you need deploy it on server.

4.1. New Seam Action

To create a New Seam Action you should select a necessary project, type a name for Seam component, POJO class, Method, Page and select a Package using Browse button.

New Seam Action Wizard

Figure 4.3. New Seam Action Wizard


You can see the action page in WebContent folder. Click on it to open in JBoss Tools HTML Editor.

Action Page in JBoss Tools HTML Editor.

Figure 4.4. Action Page in JBoss Tools HTML Editor.


Note:

You don't need to restart the server to see how the action component works. Just use context menu Run As > Run On Server.

Action component was hot-deployed. Forms and Conversations will work the same way.

Action Component

Figure 4.5. Action Component


4.2. New Seam Form

Click on actionMethod in the internal browser and add a form in your project using the New Seam Form wizard File > New > Seam Form.

Select a necessary project, type a name for Seam component, POJO class, Method, Page and select a Package using Browse button.

New Seam Form Wizard

Figure 4.6. New Seam Form Wizard


The Form Page was created in WebContent folder.

Form Page in JBoss Tools HTML Editor.

Figure 4.7. Form Page in JBoss Tools HTML Editor.


Deploy the form on server. Right click on Form Page, select Run As > Run On Server.

Form Component

Figure 4.8. Form Component


Form component was hot-deployed.

4.3. New Seam Conversation

Enter some value in the text field (e.g. value1) and click on formMethod.

Add a conversation using the New Seam Conversation wizard File > New > Seam Form.

You should select a necessary project, type a name for Seam component, POJO class, Method, Page and select a Package using Browse button.

New Seam Conversation Wizard

Figure 4.9. New Seam Conversation Wizard


Conversation page was created in WebContent folder.

Conversation Page in JBoss Tools HTML Editor.

Figure 4.10. Conversation Page in JBoss Tools HTML Editor.


Right click on Conversation page, select Run As > Run On Server.

Conversation Component

Figure 4.11. Conversation Component


Conversation component was hot-deployed.

Click on Begin and Increment buttons to check the conversation functionality.

4.4. New Seam Entity

Entities cannot be hot-deployed, so we need to stop the server.

Create an Entity using the New Entity wizard File > New > Seam Entity.

You should select a necessary project, type a name for Entity class, select a Package using Browse button, type a name for Master Page and Page.

New Seam Entity Wizard

Figure 4.12. New Seam Entity Wizard


The Master Page and the Entity were created in WebContent folder.

Master Page in JBoss Tools HTML Editor.

Figure 4.13. Master Page in JBoss Tools HTML Editor.


The Entity page is:

Entity Page in JBoss Tools HTML Editor.

Figure 4.14. Entity Page in JBoss Tools HTML Editor.


Run the Entity page on server. This is what you get:

Customer Page

Figure 4.15. Customer Page


Let's create two customers c1 and c2. Enter the name in the text field and press the Save button. Customer should be successfully created. Press Done. Do the same for c2 customer. The result should be:

Two Customers Are Created

Figure 4.16. Two Customers Are Created


Chapter 5. Seam Generate Entities

Generate Entities is available directly from within Eclipse using Hibernate Tools plugin for the standard seam-gen generation.

Generate Entities generates a set of CRUD Seam components and web pages based on existing tables in a database or on existing entities in your application.

Generate Seam Entities Wizard

Figure 5.1. Generate Seam Entities Wizard


In the Generate Seam Entities wizard there are two generation modes: Reverse Engineer from database and Use existing entities.

The Reverse Engineer from database mode can be described in four steps:

  1. The wizard get in database, extracts the tables and their connections

  2. On basis of this metainfomation the Entity classes are generated into org.domain.project.entity package

  3. For the entities from step 2 the classes EntityList and EntityHome are generated into org.domain.project.session package

  4. The xhtml pages are generated.

Checking the Use existing entities mode the wizard executes only 3 and 4 steps. It generates missing classes and xhtml pages.

Read the Generate a CRUD Database Application chapter in order to see how the Generate Seam Entities wizard can be used.

Chapter 6. Seam Editors Features

6.1. Content Assist

Content Assist (ctrl + space) is available when using expression language in:

  • JSP

  • XHTML

  • XML

  • JAVA

The Seam components are available in content assist.

Content Assist

Figure 6.1. Content Assist


6.2. OpenOn

OpenOn let's you easily navigate through your project without using the Package Explorer or Project Explorer. After pressing ctrl + left click (or just F3) you will see a corresponding method or class.

OpenOn

Figure 6.2. OpenOn


6.3. Seam Validation

Validation of various possible problematic definitions is implemented for Seam applications.

If an issue is found it will be showed in the standard Problems View.

Seam Validation

Figure 6.3. Seam Validation


In the preferences page for Seam Validator you can see and modify the validator behavior. Go to Window > Preferences > JBoss Tools > Web > Seam > Validator and select the severity level for the optional Seam Validator problem.

Seam Validator Preferences

Figure 6.4. Seam Validator Preferences


On WTP projects validation are enabled by default and thus executed automatically, but on normal Java projects you will have to go and add the Validation builder to your project . It is available in the properties of your project under Validation. The validations can be run manually by clicking Validate via the context menu on your project which will execute all the active WTP validations.

Chapter 7. Seam Views

7.1. Seam Components View

The Seam Components View is available from Seam perspective. It provides a list of seam components found in a project.

Seam Components View

Figure 7.1. Seam Components View


The Seam Components View can show a components default scope in two ways:

  • as labels on each component (click on the triangular symbol at the top of the Seam Components View page and select Scope Presentation > Label)

As label

Figure 7.2. As label


  • as a node per scope where the components are grouped under a node representing its default scope.

As node

Figure 7.3. As node


The Seam Packages can be presented in two ways:

  • Flat

Flat Presentation of Seam Packages

Figure 7.4. Flat Presentation of Seam Packages


  • Hierarchical

Hierarchical Presentation of Seam Packages

Figure 7.5. Hierarchical Presentation of Seam Packages


The Seam Component View can be filtered by choosing Customize View.

Customize View

Figure 7.6. Customize View


Select the Seam Components from Libraries under the Filters tab. This will make the view ignore components defined in jars. This will hide the many built-in Seam components and leave only those that are actually defined in the project or have been actively configured via components.xml. Therefore, deselecting the filter will show you all available components.

Selecting the Seam Components from Referenced Projects will hide the components that dependent on other project.

Available Custimozations

Figure 7.7. Available Custimozations


7.2. Project Explorer integration

If you don't like to have a view for every piece of information in Eclipse, the content of the Seam Components view is also available as a node in the built-in Project Explorer (not Package Explorer!) view in Eclipse.

Seam Components in Project Explorer

Figure 7.8. Seam Components in Project Explorer


Chapter 8. Generate a CRUD Database Application

8.1. What is CRUD?

CRUD is an acronym for the four basic types of SQL commands: Create, Read, Update, Delete. Most applications have some kind of CRUD functionality, and we can assume that every programmer had to deal with CRUD at some point. A CRUD application is one that uses forms to get data into and out of a database.

In the next chapter we will create Seam Web application, connect it to the PostgreSQL database and add CRUD support.

8.2. How to create the CRUD Database Application with Seam

  • Create a new Seam Web Project using New Project wizard or main menu File > New > Seam Web Project.

Seam Web Project Creation

Figure 8.1. Seam Web Project Creation


  • Name your project as crudapp and follow the next wizard steps keeping default settings.

    Please have a look here how to create Target Runtime and Seam Runtime in order to get started creating, running, and debugging J2EE applications.

New Seam Project Wizard

Figure 8.2. New Seam Project Wizard


  • On Seam Facet page click New... to create a new Connection profile.

Seam Facet page

Figure 8.3. Seam Facet page


  • On New Connection Profile dialog select the PostgreSQL JDBC Connection type and click Next.

New JDBC Connection Profile

Figure 8.4. New JDBC Connection Profile


  • Name your profile as cruddb and press Next.

New JDBC Connection Profile Name

Figure 8.5. New JDBC Connection Profile Name


  • On the next page click ... to select a database driver.

New JDBC Connection Profile Database Driver

Figure 8.6. New JDBC Connection Profile Database Driver


  • On Driver Definitions dialog select the PostgreSQL->8.x and click Add....

Driver Definitions List

Figure 8.7. Driver Definitions List


  • Set the location of JDBC driver and fill all other necessary fields (URL, Database Name, Password, User Id) and click OK.

Edit Driver Definition

Figure 8.8. Edit Driver Definition


  • Click OK on the next dialog with newly created driver.

Driver Definitions List

Figure 8.9. Driver Definitions List


  • Click Test Connection on the next dialog and observe that connection can be established.

Test JDBC Connection

Figure 8.10. Test JDBC Connection


JDBC Connection is OK

Figure 8.11. JDBC Connection is OK


  • Validate JDBC Connection profile settings and press Finish or Back if something is wrong.

Validate JDBC Connection settings

Figure 8.12. Validate JDBC Connection settings


  • Observe that newly created profile has been selected on Seam Facet page and click Finish.

    This will create 2 projects - crudapp and crudapp-test.

Last Step of New Seam Project Wizard

Figure 8.13. Last Step of New Seam Project Wizard


  • Have a look at the created projects. You can expand WEB_CONTENT folder and open home.xhtml or login.xhtml with JBoss Visual Editor.

CRUDAPP Seam Project

Figure 8.14. CRUDAPP Seam Project


  • Switch to Database Development perspective with Window->Open Perspective->Other... and connect to the cruddb database.

Connecting to the CRUDDB database

Figure 8.15. Connecting to the CRUDDB database


  • Expand cruddb nodes to view its Schemas, Tables, Columns etc.

CRUDDB Database

Figure 8.16. CRUDDB Database


  • Switch back to the Seam perspective. From the toolbar select New->Seam Generate Entities to create a set of CRUD Seam components and web pages based on existing tables in the database. In the Generate Seam Entities dialog keep everything by default and press Finish.

Generate Seam Entities

Figure 8.17. Generate Seam Entities


  • Under WebContent folder you can find a lot of generated xhtml files:

Entities Web Pages

Figure 8.18. Entities Web Pages


  • And under src folder java classes are created.

Entities Java Classes

Figure 8.19. Entities Java Classes


  • Switch to Hibernate perspective with Window->Open Perspective->Other.... On Hibernate Configurations view expand the crudapp configuration. Right click on Customers and select Open Mapping Diagram from the popup menu.

Hibernate Configurations View

Figure 8.20. Hibernate Configurations View


  • Observe that Mapping Diagram is opened in the editor. Here you can see the relations between models and database tables. Select Customers entity model, right click and select Open Source File.

Mapping Diagram

Figure 8.21. Mapping Diagram


  • This will open the Customers.java file in the java editor.

Entity class from Mapping Diagram

Figure 8.22. Entity class from Mapping Diagram


After that you are ready to deploy your application to J2EE application server. This is described in the next chapter.

Chapter 9. The CRUD Application Walkthrough

9.1. Using CRUD Application

To run your CRUD Application you should do the following steps:

  • Start JBoss Application Server if it was not started before.

On JBossServer View right click on the JBoss Application Server and select Start

Start the Server

Figure 9.1. Start the Server


  • Run a project on the Server.

On Package Explorer View right click on the crudapp project, select Run As > Run on Server.

Run Project on Server

Figure 9.2. Run Project on Server


Select a Server and click Finish

Select a Server

Figure 9.3. Select a Server


Home page of the crudapp project should appear in Web Browser.

Home page

Figure 9.4. Home page


After that you can use CRUD application with "employee" database.

You can use internal JBDS Web Browser or your external Web Browser with the same link (http://localhost:8080/crudapp/home.seam).

Click on the Employees List link and observe that data from employee database is displayed.

Employees List

Figure 9.5. Employees List


Use Employees search parameters fields to filter the selected list.

Press Select opposite one of employees.

Employee details

Figure 9.6. Employee details


Press Edit to edit employee fields.

Enter Login and Password to login. (Use "crudapp-user"/"secret" for example)

Login page

Figure 9.7. Login page


Edit Employee

Figure 9.8. Edit Employee


Fill in firstname and press Update.

Database will be updated.

Chapter 10. Using TestNG project

10.1. What is TestNG?

TestNG ("Testing, the Next Generation") is a Java unit testing framework that aims to overcome many limitations of JUnit. TestNG introduces some new functionalities that make it more powerful and easier to use, such as:

  • JDK 5 Annotations (JDK 1.4 is also supported with JavaDoc annotations)

  • Flexible test configuration

  • Support for data-driven testing (with @DataProvider)

  • Support for parameters

  • Allows distribution of tests on slave machines

  • Powerful execution model (no more TestSuite)

  • Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, etc...)

  • Embeds BeanShell for further flexibility

  • Default JDK functions for runtime and logging (no dependencies)

  • Dependent methods for application server testing

More information can be found on home page: www.testng.org

10.3. How to use the generated Seam-test project to run Seam tests?

  • Create a new Seam Web Project with EAR deployment using the New Seam Project wizard.

  • After a project is created you will have the generated Seam-test project that is setup to run TestNG directly against the proper libraries and server runtime libraries.

Seam-test Project

Figure 10.1. Seam-test Project


  • Add Seam Action to your project via File > New > Seam Action.

Seam Action Creation

Figure 10.2. Seam Action Creation


  • Fill out the wizard fields. New Seam Action wizard will create resources and place them in the appropriate folders dependent on EAR project structure.

New Seam Action Wizard

Figure 10.3. New Seam Action Wizard


  • When Action is created you will see actionPage.xhtml in Package Explorer view. ActionBean.java will be automatically opened in Java Editor.

Created Action

Figure 10.4. Created Action


  • Select ActionLocalTest.xml in Seam-test project and run the test with right click Run As > TestNG Suite.

Running TestNG

Figure 10.5. Running TestNG


The test process will start and its output will be written in Console View.

Test is Finished

Figure 10.6. Test is Finished


  • After running TestNG you will have the test results in test-output folder in Seam-test project (press F5 to refresh the Package Explorer view). Open index.html file with Web Browser or simply use the TestNG view.

The below view shows a successful run of the test.

Viewing the Test Results

Figure 10.7. Viewing the Test Results


You can see the test results in Web Browser.

Test Results in Browser

Figure 10.8. Test Results in Browser


After clicking on ActionLocal Tests link you will see the Results for ActionLocal Tests.

Test Information

Figure 10.9. Test Information


Select a result on the left-hand pane and its details will be displayed on the right-hand one.

ActionLocal Test Details

Figure 10.10. ActionLocal Test Details