HelloWorldSeam
From EBSSWiki
Pre-requisites of Test Application Using Seam 202, Rich faces 3.2.1 and PostgreSQL
Step 1:Let’s create the tablespace, database user, database and table using following commands :=>
--New Role: testuser / testpass
CREATE ROLE testuser LOGIN PASSWORD 'testpass' NOINHERIT VALID UNTIL 'infinity';
--New Tablespace - testts mapped to C:\data\testdb
CREATE TABLESPACE testts OWNER testuser LOCATION 'C:\\data\\testdb';
--New Database - testdb
CREATE DATABASE testdb WITH ENCODING='UTF8' OWNER=testuser TABLESPACE=testts;
--New Table – users
CREATE TABLE users ( email varchar(20) NOT NULL, passwd varchar(50) NOT NULL, firstname varchar(50) NOT NULL, lastname varchar(50) NOT NULL, CONSTRAINT users_pk PRIMARY KEY (email) )WITHOUT OIDS Tablespace testts ; ALTER TABLE users OWNER TO testuser;
--New Table - country
CREATE TABLE country ( code varchar(20) NOT NULL, name varchar(50) NOT NULL, pos int2 NOT NULL, CONSTRAINT country_pk PRIMARY KEY (code) )WITHOUT OIDS tablespace testts; ALTER TABLE country OWNER TO testuser;
--New Table - supplier
CREATE TABLE supplier ( code varchar(20) NOT NULL, name varchar(100) NOT NULL, addr1 varchar(100) NOT NULL, addr2 varchar(100), addr3 varchar(100), city varchar(100) NOT NULL, CONSTRAINT supplier_pk PRIMARY KEY (code) )WITHOUT OIDS tablespace testts; ALTER TABLE supplier OWNER TO testuser;
Step 2: Unzip Seam 2.0.2.GA zip file at C:\ and rename it as C:\seam202.
Step 3: Unzip RichFaces 3.2.1.GA zip file at C:\.
Step 4: Copy PostgreSQL driver executable jar file (postgresql-8.1-409.jdbc3.jar) inside C:\seam202\lib\gen folder.Create gen folder if that doesn’t exist under lib folder of seam 202.
tep 5: Copy Rich faces 3.2.1 Library files inside C:\seam202\lib folder and rename them as under:=>
Richfaces-api-3.2.1.GA.jar as richfaces-api.jar Richfaces-impl-3.2.1.GA.jar as richfaces-impl.jar Richfaces-ui-3.2.1.GA.jar as richfaces-ui.jar
Step 6: Create workspace directory as C:\studytemp\testws for the application which we will be creating using seam-gen utility.
Step 7: Create workspace directory as C:\study\testws for the MyEclipse application.
Step 8: Copy the default server inside C:\jboss422\server directory and rename it to default.bak as seam-gen will deploy our application inside the deploy directory of default server.
Step 9: Copy the default.bak server inside C:\jboss422\server directory and rename it to
test as we will be requiring this for deploying our MyEclipse project.
Creating Test Application using Seam-gen Utility
Step 1: Go to command prompt on type cd \seam202.
Press Enter to change directory.
Step 2: Given following commands to setup the Seam project configurations :=>
Step 2.1: seam setup.
Press Enter. This will set up initial configurations for your application.
If you are running this command for the first time, it will download few files and will copy them inside you C:\seam202\lib\gen folder
After this please input the following details (Press Enter Key after inserting each value to proceed further) :=>
Enter your Java project workspace = C: /studytemp/testws
Enter your JBoss home directory = C:/jboss422
Do you want to use ICE Faces instead of RichFaces [n] (y, [n]) = Type n for No.
Select a RichFaces skin [blueSky] ([blueSky], classic, ruby, wine, deepMarine, emeraldTown, sakura, DEFAULT) = blueSky
Is this project deployed as an EAR (with EJB components) or a WAR (with no EJB support) [ear] ([ear], war) = ear
Enter the Java package name for your session beans [com.sfbl.action]
[com.sfbl.action] = com.sfbl.action
Enter the Java package name for your entity beans [com.sfbl.model]
[com.sfbl.model] = com.sfbl.model
Enter the Java package name for your test cases [com.sfbl.test]
[com.sfbl.test] = com.sfbl.test
What kind of database are you using? [postgres] (hsql, mysql, oracle
,[postgres], mssql, db2, sybase, enterprisedb, h2) = postgres
Enter the Hibernate dialect for your database [org.hibernate.dialect.PostgreSQLDialect] [org.hibernate.dialect.PostgreSQLDialect] = Just Press Enter here as we have to use the default value in this case org.hibernate.dialect .PostgreSQLDialect.
Enter the filesystem path to the JDBC driver jar [../lib/gen/postgre
sql-8.1-409.jdbc3.jar] [../lib/gen/postgresql-8.1-409.jdbc3.jar] =
../lib/gen/postgresql-8.1-409.jdbc3.jar
I’ve added my PostgreSQL Driver’s executable jar inside C:\seam202\lib\gen folder. For this I created gen folder initially.
Enter JDBC driver class for your database [org.postgresql.Driver] [o
rg.postgresql.Driver] = Just hit Enter here to input default value.
Enter the JDBC URL for your database [jdbc:postgresql://localhost:54
32/testdb] [jdbc:postgresql://localhost:5432/testdb] = jdbc:postgresql://localhost:5432/testdb
Enter database username [testuser] [testuser] = testuser
Enter database password [testpass] [testpass] = testpass
Enter the database schema name (it is OK to leave this blank) [public] [public] = public
Enter the database catalog name (it is OK to leave this blank) [] [] = Just hit enter without inputting any text as there is no Catalog available for PostgreSQL database
Are you working with tables that already exist in the database? [y]
([y], n) = Type y for Yes.
Do you want to drop and recreate the database tables and data in import.sql
each time you deploy? [n] (y, [n]) = Type n for No.
You should be able to view the Build Successful message on command prompt as follows: =>
Step 2.2: seam create-project. Press Enter.
This will create the project in your workspace directory.
You can view Build Successful message on successful creation of Project.
Step 2.3: seam generate. Press Enter.
This will help to associate the database connectivity with the application.
It will also add exploded archives into your project.
Step 2.4: seam explode. Press Enter.
This will set up the dependencies and will add database configuration xml file and
will deploy ear file of our project inside JBoss default server’s deploy folder.
Step 3: Now start the JBoss Default Server using following commands :=>
Step 3.1: Type cd \jboss422\bin command on command prompt. Press Enter.
Step 3.2: Start the server using run command. Press Enter.
It might take a minute to start the server as Seam will be initializing components etc.
Step 4: Open the browser window and type the following URL in your address bar :=>
This will take you to the home page of your application
If you click on UsersList link you can view the records that are available in
your users table in the database.
For creation/edition/deletion of any data one has login into the system.
Step 5: Before proceeding further please close this browser window
shut down the server by using Ctrl+C command on command prompt.
