HalloWorld using Seam with the IDE Netbeans 6.5 on Glassfish
Algemeen
This manual explains how to use Seam with Netbeans 6.5. on Glassfish. I've found other manuals on the internet, but only by combining the information from them I could use Seam. This is why I created this manual because it's quite simple the use Seam on Netbeans.
On this moment I have some pilot projects for using Seam, Glassfish and Netbeans for my clients. If you live in the Netherlands and you would like to work with Seam you can contact me. See also the vacancy on the following link which is in Dutch
Gezocht een Java'er met een praktische instellingVersion control
| Version | Date | Adjustments |
| 0.5 | 22-Feb-2009 | Textual Description in Dutch |
| 1.0. | 25-Feb-2009 | Added images |
| 1.1 | 27-Feb-2009 | Translation to English |
Version Control
Manual
In this manual the steps for making a simple Seam application with the help of Netbeans is explained. The following steps are needed:
- Download the Seam jars
- Create a webproject in Netbeans
- Add the Seam jars to the webproject
- Add a default locale in de faces-config.xml
- Adjust web.xml for using Seam
- Adjust the file welcomeJSF.jsp
- Create the JavaBean for HelloWorld
- Add the file seam.properties to the src-directory
Download the Seam jars
Before starting a Seam Project in Netbeans it is first necessary to download the needed jars for Saem. You can download this jars from
JBoss Seam. In this manual JBoss Seam 2.1.1 is used.
Unpack the downloaded zip-file and copy the needed jars for Seam to a separate directory. You could name this directory Seam Jars. Below I show the needed jars, which are more than strict necessary for this example but serve for using added functionalities in the future.
- commons-logging.jar
- hibernate-all.jar
- jboss-el.jar
- jboss-seam.jar
- jboss-seam-debug.jar
- jboss-seam-gen.jar
- jboss-seam-ioc.jar
- jboss-seam-mail.jar
- jboss-seam-pdf.jar
- jboss-seam-remoting.jar
- jboss-seam-ui.jar
- testng.jar
- thirdparty-all.jar
Create a webproject in Netbeans
Start Netbeans 6.5 en create a new Web-Project. You can do this by completing the following steps. Click an the new Project button (Ctrl+Shift+N).
 |
| NetBeans Create New Project |
Choose Java Web and then Web Application
 |
| NetBeans Create new webproject |
As a name choose HalloWorld.
 |
| NetBeans Create WebProject screen1 |
As a server choose GlassFish V2
 |
| NetBeans Create Webproject screen2 |
and select the framework Java Server Faces.
 |
| Netbeans New WebProject Screen3 |
Press then the Finish-knop. There will be a new web project created within Netbeans
Add the Seam jars to the webproject
Now for making Seam to work it's needed to add the Seam Jar to the project. Go the newly created project en press the right mouse button and choose properties.
 |
| NetBeans Project Properties |
Choose within this menu for libraries
 |
| NetBeans Add Libraries |
Press on the button Add Library
 |
| NetBeans button Add Library |
and add the following libraries
 |
| NetBeans Select Facelets Libraries |
- Facelets 1.1.14
- Facelets 1.1.14 EL Api
Now a new extra library will be created within Netbeans 6.5. which will be called JBossSeam. The jar files which we have added in the separate directory will be put in this library. Press on the Create button
 |
| NetBeans Add Library Create button |
and give the library the name JBossSeam
 |
| NetBeans Create Library JBossSeam |
add the Seam jars to the library
 |
| NetBeans Select Jars to Add New Library |
After completion there are 3 libraries added to the project
 |
| NetBeans Seam Library Added |
Add a default locale in de faces-config.xml
If the project is now deployed on Glassfish there will be an error message. The deploying of the project can be done by the following steps. Just Press the F6-button or select the project and press on the right mouse button en choose then run.
 |
| NetBeans Run Project |
In the Glassfish log you wil see the next error message
java.lang.NullPointerException
at org.jboss.seam.jsf.SeamViewHandler.calculateLocale(SeamViewHandler.java:55)
at com.sun.faces.application.ViewHandlerImpl.createView(ViewHandlerImpl.java:350)
at org.jboss.seam.jsf.SeamViewHandler.createView(SeamViewHandler.java:68)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:203)
The reason is that there is no default locale added within the file faces-config.xml. You can solve this by following the next steps. Go the the WEB-INF directory within the HelloWord proejct and open the faces-config.xml file.
 |
| NetBeans Open Faces-Config.xml |
Press on the XML-button
 |
| NetBeans XML-button FacesConfig.xml |
Add the following to the faces-config.xml
 |
| FacesConfig.xml |
Adjust web.xml for using Seam
Now we need to adjust web.xml so we can use the Seam functionality. Adjust the file web.xml. This can be done by opening the file
 |
| NetBeans Open web.xml |
and press on the XML-button
 |
| NetBeans XML button web.xml |
Just add the following to the web.xml
 |
| Seam added to web.xml |
If you deploy the application by pressing the F6-button then you will see in the webbrowser Java Server Faces. We will change this in Hallo World
Adjust the file welcomeJSF.jsp
For adjusting the file welcomJSF.jsp we will take the following steps. Go within the project to the file welcomeJSF
 |
| NetBeans welcomeJSF.jsp |
and change the the file to
 |
| HalloWorld.jsp |
If you now deploy the project the browser will show nothing. The reason is that the JavaBean for HalloWorld is not created.
Create the JavaBean for HelloWorld
Before creating the JavaBean we need the have a package. So we first create a package by following the next steps
 |
| NetBeans Add a Java Package |
Give the package the name nl.wtell.test
 |
| Package nl.wtell.test |
Add to this package the Java-class nl.wtell.test.halloworld
 |
| NetBeans Adding a Java Class |
Give this class now the following contents
 |
| HelloWorld.class |
If you deploy this project by pressing the F6 button you will see nothing. How is this possible? We have created the class!!!
Add the file seam.properties to the src-directory
For making Seam to work you need to add an empty file seam.properties to the source directory. Just follow the next steps. Go the the directory Source Package and choose for the option Create a new File and give it the name seam.properties.
 |
| NetBeans Create a new File |
The next step is giving the file the name seam.properties
 |
| New File with the name seam.properties |
If you completed all steps you will see by deploying this project on GlassFish HelloWorld on the webbrowser. Perfect. You have done a good job and good luck by using Seam.
 |
| Hallo World on the webbrowser |