Introduction
Après avoir effectué la configuration de l’environnement permettant de faire fonctionner le framework JBoss seam dans le l’article Jboss seam premier pas getting started, nous allons maintenant pouvoir créer notre premier projet.
Configuration de l’environnement avec seam setup
C:\>seam setup
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre1.6.0_04\lib\tools.jar
Buildfile: C:\java\jboss-seam-2.0.1.GA\seam-gen\build.xml
init:
setup:
[echo] Welcome to seam-gen 
[input] Enter your Java project workspace (the directory that contains your Seam projects) [C:/Projects] [C:/Projects]
C:\java\workspace
[input] Enter your JBoss home directory [C:/Program Files/jboss-4.2.2.GA] [C:/Program Files/jboss-4.2.2.GA]
C:\java\jboss-4.2.2.GA
[input] Enter the project name [myproject] [myproject]
HelloWorld
[echo] Accepted project name as: HelloWorld
[input] Do you want to use ICEFaces instead of RichFaces [n] (y, [n], )
n
[input] skipping input as property icefaces.home.new has already been set.
[input] Select a RichFaces skin [blueSky] ([blueSky], classic, ruby, wine, deepMarine, emeraldTown, sakura, DEFAULT)
ruby
[input] Is this project deployed as an EAR (with EJB components) or a WAR (with no EJB support) [ear] ([ear], war, )
war (ca fait riche un ear pour faire un hello world)
[input] Enter the Java package name for your session beans [com.mydomain.HelloWorld] [com.mydomain.HelloWorld]
[input] Enter the Java package name for your entity beans [com.mydomain.HelloWorld] [com.mydomain.HelloWorld]
[input] Enter the Java package name for your test cases [com.mydomain.HelloWorld.test][com.mydomain.HelloWorld.test]
[input] What kind of database are you using? [hsql] ([hsql], mysql, oracle, postgres, mssql, db2, sybase, enterprisedb, h2)
[input] Enter the Hibernate dialect for your database [org.hibernate.dialect.HSQLDialect] [org.hibernate.dialect.HSQLDialect]
[input] Enter the filesystem path to the JDBC driver jar [lib/hsqldb.jar] [lib/hsqldb.jar]
C:\java\jboss-4.2.2.GA\server\all\lib\hsqldb.jar
[input] Enter JDBC driver class for your database [org.hsqldb.jdbcDriver] [org.hsqldb.jdbcDriver]
[input] Enter the JDBC URL for your database [jdbc:hsqldb:.] [jdbc:hsqldb:.]
jdbc:hsqldb:mem:helloWorldDb
[input] Enter database username [sa] [sa]
[input] Enter database password [] []
[input] Enter the database schema name (it is OK to leave this blank) [] []
[input] Enter the database catalog name (it is OK to leave this blank) [] []
[input] Are you working with tables that already exist in the database? [n] (y, [n], )
[input] Do you want to drop and recreate the database tables and data in import.sql each time you deploy? [n] (y, [n], )
y
[propertyfile] Creating new property file: C:\java\jboss-seam-2.0.1.GA\seam-gen\build.properties
[echo] Installing JDBC driver jar to JBoss server
[echo] Type ’seam create-project’ to create the new project
BUILD SUCCESSFUL
Total time: 3 minutes 16 seconds
C:\>
Création d’un nouveau projet avec seam new-project
Voilà notre premier projet configuré, maintenant il faut le créer avec la commande :
seam new-project
La structure du projet a été créée dans le workspace indiqué précédement. Les jars seam vont y être copiés, les templates facelets, les métédatas Eclipse, les scripts de build Ant.
Copier le war explosé dans le répertoire adéquat du serveur jboss avec la commande :
seam explode
Importer et démarrer l’application dans JBOSS TOOLS
Afin de pouvoir modifier les fichiers dans l’IDE, il faut :
File > new > Project > sélectionnez Général > Project (ne pas sélectionner projet java)
Project name : helloworld
Maintenant afin de voir les traces dans la console eclipse, nous allons ajouter dans la view server, notre serveur jboss :
Windows > show view > sélectionnez servers
Dans la view nouvellement ouverte, clic droit new server et sélectionnez le server JBOSS AS 4.2
Cliquez sur next
Home directory : C:\java\jboss-4.2.2.GA

Choisissez le serveur default et cliquez sur finish
Maintenant démarrez le serveur nouvelle ajouté, si vous regardez bien la console, vous verrez l’application helloworld démarrer.
Afficher dans votre navigateur http://localhost:8080/helloworld/
Vous devriez voir quelque chose ressemblant à çà :

Afin de tester une fonctionnalité intéressant de JBOSS :
Modifiez par exemple de fichier web.xml se trouvant dans ressources > WEB-INF
Modifiez la valeur du noeud
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>ruby</param-value>
</context-param>
par
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>pop</param-value>
</context-param>
Lorsque vous allez sauvegarder vos modifications, observez la console
on peut observer que le fichier modifié a directement été copié dans
[copy] Copying 3 files to Y:\java\jboss-4.2.2.GA\server\default\deploy\helloworld.war
Et que sans redémarrer votre serveur, la modification a été prise en compte. Que de temps gagné (ceux qui ont codé sur des gros projets avec maven, spring et Eclipse me comprendront), raffraichissez votre page et observez le nouveau thème appliqué au projet :

Création de la page helloWorld
Nous allons pour cela créér unenouvelle action avec la commande :
seam new-action
C:\dev\projects>seam new-action
Buildfile: C:\java\jboss-seam-2.0.1.GA\seam-gen\build.xml
init:
init-properties:
[echo] C:/java/jboss-4.2.2.GA
validate-workspace:
validate-project:
action-input:
[input] Enter the Seam component name
sayHelloWorld
[input] Enter the local interface name [SayHelloWorld] [SayHelloWorld]
[input] Enter the bean class name [SayHelloWorldBean] [SayHelloWorldBean]
[input] Enter the action method name [sayHelloWorld] [sayHelloWorld]
[input] Enter the page name [sayHelloWorld] [sayHelloWorld]
setup-filters:
new-action-ear:
new-action-war:
[echo] Creating a new JavaBean component with an action method
[copy] Copying 1 file to C:\java\workspace\HelloWorld\src\action\com\mydomain\HelloWorld
[copy] Copying 1 file to C:\java\workspace\HelloWorld\src\test\com\mydomain\HelloWorld\test
[copy] Copying 1 file to C:\java\workspace\HelloWorld\src\test\com\mydomain\HelloWorld\test
[copy] Copying 1 file to C:\java\workspace\HelloWorld\view
[echo] Type ’seam explode’ and go to http://localhost:8080/HelloWorld/sayHelloWorld.seam
new-action:
BUILD SUCCESSFUL
Total time: 31 seconds
C:\dev\projects>
La création d’une action nécessite de redémarrer le serveur, faites le avec la commande :
seam restart
Votre serveur d’application devrait redéployer tout seul l’application helloworld
Afin de voir notre helloworld, il suffit maintenant d’afficher la page http://localhost:8080/HelloWorld/sayHelloWorld.seam
Vous devriez voir la page suivante s’afficher :

Afin que l’application fasse ce qu’on lui demande, c’est à dire “dire bonjour”, il ne vous reste plus qu’a cliquer sur le bouton sayHelloWorld qui lancera la méthode sayHelloWorld de l’action que nous venons de créer.
public void sayHelloWorld()
{
//implement your business logic here
log.info(”sayHelloWorld.sayHelloWorld() action called”);
facesMessages.add(”sayHelloWorld”);
}