HelloWorldSeam

From EBSSWiki

Jump to: navigation, search

Contents

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.



Image:01.HelloWorldSeam.JPG

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.

Image:02.HelloWorldSeam.JPG

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

Image:03.HelloWorldSeam.JPG

Enter your JBoss home directory = C:/jboss422

Image:04.HelloWorldSeam.JPG

Enter the project name = test

Image:05.HelloWorldSeam.JPG

Do you want to use ICE Faces instead of RichFaces [n] (y, [n]) = Type n for No.

Image:06.HelloWorldSeam.JPG

Select a RichFaces skin [blueSky] ([blueSky], classic, ruby, wine, deepMarine, emeraldTown, sakura, DEFAULT) = blueSky

Image:07.HelloWorldSeam.JPG

Is this project deployed as an EAR (with EJB components) or a WAR (with no EJB support) [ear] ([ear], war) = ear

Image:08.HelloWorldSeam.JPG

Enter the Java package name for your session beans [com.sfbl.action] [com.sfbl.action] = com.sfbl.action

Image:09.HelloWorldSeam.JPG

Enter the Java package name for your entity beans [com.sfbl.model] [com.sfbl.model] = com.sfbl.model

Image:10.HelloWorldSeam.JPG

Enter the Java package name for your test cases [com.sfbl.test] [com.sfbl.test] = com.sfbl.test

Image:11.HelloWorldSeam.JPG

What kind of database are you using? [postgres] (hsql, mysql, oracle ,[postgres], mssql, db2, sybase, enterprisedb, h2) = postgres

Image:12.HelloWorldSeam.JPG

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.

Image:13.HelloWorldSeam.JPG

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.

Image:14.HelloWorldSeam.JPG

Enter JDBC driver class for your database [org.postgresql.Driver] [o rg.postgresql.Driver] = Just hit Enter here to input default value.

Image:15.HelloWorldSeam.JPG

Enter the JDBC URL for your database [jdbc:postgresql://localhost:54 32/testdb] [jdbc:postgresql://localhost:5432/testdb] = jdbc:postgresql://localhost:5432/testdb

Image:16.HelloWorldSeam.JPG

Enter database username [testuser] [testuser] = testuser

Image:17.HelloWorldSeam.JPG

Enter database password [testpass] [testpass] = testpass

Image:18.HelloWorldSeam.JPG

Enter the database schema name (it is OK to leave this blank) [public] [public] = public

Image:19.HelloWorldSeam.JPG

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

Image:20.HelloWorldSeam.JPG

Are you working with tables that already exist in the database? [y] ([y], n) = Type y for Yes.

Image:21.HelloWorldSeam.JPG

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.

Image:22.HelloWorldSeam.JPG

You should be able to view the Build Successful message on command prompt as follows: =>

Image:23.HelloWorldSeam.JPG


Step 2.2: seam create-project. Press Enter.



Image:24.HelloWorldSeam.JPG

This will create the project in your workspace directory.

Image:25.HelloWorldSeam.JPG

You can view Build Successful message on successful creation of Project.


Step 2.3: seam generate. Press Enter.



Image:26.HelloWorldSeam.JPG

This will help to associate the database connectivity with the application.
It will also add exploded archives into your project.

Image:27.HelloWorldSeam.JPG


Step 2.4: seam explode. Press Enter.



Image:28.HelloWorldSeam.JPG

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.

Image:29.HelloWorldSeam.JPG


Step 3: Now start the JBoss Default Server using following commands :=>


Step 3.1: Type cd \jboss422\bin command on command prompt. Press Enter.



Image:30.HelloWorldSeam.JPG

Step 3.2: Start the server using run command. Press Enter.

Image:31.HelloWorldSeam.JPG

Image:32.HelloWorldSeam.JPG

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 :=>


http://localhost:8080/test/

Image:33.HelloWorldSeam.JPG

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.

Image:34.HelloWorldSeam.JPG

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.

Personal tools