Un exercici amb el Framework Seam (i 2, amb Seam 2.3.0)

Al darrer post anunciava que repetiria la creació de l’aplicació de biblioteca amb les eines de la versió 2.3.0 del Framework Seam.

Farem l’exercici sobre un servidor Boss AS 7.1.1 Final
Podeu obtenir-lo aquí: http://download.jboss.org/jbossas/7.1/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final.zip

Ens cal una versió de JDK a partir de la 1.6 (feu un cop d’ull a http://www.oracle.com/technetwork/java/javase/downloads/index.html).

Finalment, la versió de Seam 2.3.0 la descarrego de
Seam 2.3.0 GA http://sourceforge.net/projects/jboss/files/JBoss%20Seam/2.3.0.Final/

El primer que ens crida l’atenció és que la mida del Framewrok Seam 2.3.0 és molt més gran que la del Seam 3.1.0. Això ens diu alguna cosa sobre el canvi d’orientació que va prendre el desenvolupament del Framework Seam amb el canvi de versions. De fet, ara mateix sembla que els esforços de l’equip dque ha desenvolupat Seam estan orientats al desenvolupament de DeltaSpike (“Apache DeltaSpike is a collection of JSR-299 (CDI) Extensions for building applications on the Java SE and EE platforms”). Si algun dia hi ha un Seam 4, és probable que el seu core sigui DeltaSpike.

Tanmateix, l’eina és allà i és útil, actual i potent. Per tant, tenint en ment el futur del Seam, que passa per aprofundir en la CDI, passo a repetir el desenvolupament de la biblioteca amb Seam 2.3.0.

Recordem les especificacions:

– una taula per guardar els llibres (id, llibre, isbn, id_ubicació, id_format);
– una taula d’autors (id, autor);
– una taula de relació m-n entre llibres i autors (un autor pot haver escrit molts llibres, un llibre pot ser escrit per molts autors. Per tant: id, id_autor, id_llibre);
– una taula de relació m-n entre llibres i temàtiques (un llibre pot tractar diversos temes; un tema pot ser tractat per molts llibres. Per tant, id, id_llibre, id_tematica);
– lògicament, doncs, una taula de temàtiques (id, tematica).
– una taula d’ubicacions (id, lloc) ja que puc tenir llibres per uns quants llocs de la casa, a prestatges, o a DVDs…
– una taula de formats: “paper”, “pdf”, “epub”, “cbr”… (id, format).

Faig servir el servidor MySQL que em ve amb el XAMPP que tinc instal·lat. Amb el phpMyAdmin creo una nova base de dades “prova_seam” i importo l’esquema del següent script:

esquema.sql

-- phpMyAdmin SQL Dump
-- version 3.4.5
-- http://www.phpmyadmin.net
--
-- Servidor: localhost
-- Tiempo de generación: 21-11-2012 a las 21:05:25
-- Versión del servidor: 5.5.16
-- Versión de PHP: 5.3.8

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Base de datos: `prova_seam`
--

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `autor`
--

CREATE TABLE IF NOT EXISTS `autor` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `autor` varchar(100) COLLATE latin1_spanish_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci AUTO_INCREMENT=2 ;

--
-- Volcado de datos para la tabla `autor`
--


-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `format`
--

CREATE TABLE IF NOT EXISTS `format` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `format` varchar(100) COLLATE latin1_spanish_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci AUTO_INCREMENT=2 ;

--
-- Volcado de datos para la tabla `format`
--


-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `llibre`
--

CREATE TABLE IF NOT EXISTS `llibre` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `llibre` varchar(200) COLLATE latin1_spanish_ci NOT NULL,
  `isbn` varchar(13) COLLATE latin1_spanish_ci NOT NULL,
  `id_ubicacio` int(11) NOT NULL,
  `id_format` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `id_ubicacio` (`id_ubicacio`),
  KEY `id_format` (`id_format`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `llibre_autor`
--

CREATE TABLE IF NOT EXISTS `llibre_autor` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_llibre` int(11) NOT NULL,
  `id_autor` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `id_llibre` (`id_llibre`),
  KEY `id_autor` (`id_autor`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `llibre_tematica`
--

CREATE TABLE IF NOT EXISTS `llibre_tematica` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_autor` int(11) NOT NULL,
  `id_tematica` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `id_autor` (`id_autor`),
  KEY `id_tematica` (`id_tematica`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `tematica`
--

CREATE TABLE IF NOT EXISTS `tematica` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `tematica` varchar(100) COLLATE latin1_spanish_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci AUTO_INCREMENT=1 ;

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `ubicacio`
--

CREATE TABLE IF NOT EXISTS `ubicacio` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ubicacio` varchar(100) COLLATE latin1_spanish_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 COLLATE=latin1_spanish_ci AUTO_INCREMENT=2 ;


--
-- Restricciones para tablas volcadas
--

--
-- Filtros para la tabla `llibre`
--
ALTER TABLE `llibre`
  ADD CONSTRAINT `llibre_ibfk_1` FOREIGN KEY (`id_ubicacio`) REFERENCES `ubicacio` (`id`),
  ADD CONSTRAINT `llibre_ibfk_2` FOREIGN KEY (`id_format`) REFERENCES `format` (`id`);

--
-- Filtros para la tabla `llibre_autor`
--
ALTER TABLE `llibre_autor`
  ADD CONSTRAINT `llibre_autor_ibfk_1` FOREIGN KEY (`id_llibre`) REFERENCES `llibre` (`id`),
  ADD CONSTRAINT `llibre_autor_ibfk_2` FOREIGN KEY (`id_autor`) REFERENCES `autor` (`id`);

--
-- Filtros para la tabla `llibre_tematica`
--
ALTER TABLE `llibre_tematica`
  ADD CONSTRAINT `llibre_tematica_ibfk_1` FOREIGN KEY (`id_autor`) REFERENCES `autor` (`id`),
  ADD CONSTRAINT `llibre_tematica_ibfk_2` FOREIGN KEY (`id_tematica`) REFERENCES `tematica` (`id`);

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

És molt important definir correctament les restriccions,les foreign-keys i posar un id a totes les entitats. 

Comencem. A diferència de Seam 3.1.0, amb Forge, amb Seam 2.3.0 disposo d'una eina integrada al framework, el seam-gen que em permet realitzar totes les tasques de creació d'entitats, scaffolding, o enginyeria inversa de les taules de la base de dades. 

Obro un terminal a la carpeta home del Jboss-Seam 2.3.0 Final i examino l'eina. faig seam help per examinar les diferents opcions:

albert@athena:~/jboss-seam/jboss-seam-2.3.0.Final$ seam help
SEAM_HOME: /home/albert/jboss-seam/jboss-seam-2.3.0.Final
Using seam-gen sources from: /home/albert/jboss-seam/jboss-seam-2.3.0.Final/seam-gen
NAME
   seam (aka seam-gen) - Execute seam code generation.

   The seam.bat (Windows) and seam (Linux/Unix) scripts support
   commands that use Ant build targets to set up a Seam project and
   generate source code. Ant is not required to be on your path to
   use this script.
   
   JBoss AS must be installed to deploy the project (JBoss AS 7.1.1 is strongly recommended).

SYNOPSIS
   seam COMMAND

SEAM PROJECT SETUP/DEPLOYMENT COMMANDS
   setup
      Run the wizard used to set various properties in the
      seam-gen/build.properties file. This task establishes the
      location of your project workspace and your JBoss AS home
      directory. It also captures settings for code generation, such
      as the Java packages used for the model, action, and test
      classes, and database connection information.

      You can hand edit the seam-gen/build.properties file instead of
      using this command.

      Example: seam setup

   create-project
      Create a new Seam project workspace that includes all the
      required dependencies, a build script, and two configuration
      profiles (dev and prod). Uses the project attributes defined in
      seam-gen/build.properties. Also generates Eclipse, NetBeans and
      IDEA project files, allowing the project to be quickly imported.

      Example: seam create-project

   update-project
      Update the project workspace with the latest library
      dependencies.

      Example: seam update-project

   delete-project
      Delete the project workspace. Also undeploys the project from
      the JBoss server.

      WARNING: This command is permanent! There is no undo!

      Example: seam delete-project

   archive
      Build the project archive (packaged EAR or WAR) and place
      it in the dist folder in the root of the project.

      Example: seam archive

   deploy
      Deploy the project archive (packaged EAR or WAR) and the
      datasource to the JBoss server.

      Example: seam deploy

   undeploy
      Undeploy the project archive (packaged EAR or WAR) and the
      datasource from the JBoss server.

      Example: seam undeploy

   explode
      Deploy the project archive (exploded EAR or WAR directory
      structure) and the datasource to the JBoss server.

      Example: seam explode

   restart
      Restart the project archive that was previously deployed as an
      exploded directory structure.

      Example: seam restart

   unexplode
      Undeploy the project archive (exploded EAR or WAR directory
      structure) and the datasource from the JBoss server.

      Example: seam unexplode

SEAM CODE GENERATION COMMANDS
   new-action
      Create a new Java interface and SLSB with key Seam/EJB3
      annotations.

      Example: seam new-action

   new-form
      Create a new Java interface and SFSB with key Seam/EJB3
      annotations, and associated xhtml view. Also, create a new
      JUnit ARQ test case that can be used to simulate a JSF
      request/response and standard JUnit type tests.

      Example: seam new-form

   new-conversation
      Create a new Java interface and SFSB with key Seam/EJB3
      annotations. Adds annotations and stub methods for @Begin and
      @End.

      Example: seam new-conversation

   new-entity
      Create a new entity bean with key Seam/EJB3 annotations with
      example attributes.

      Example: seam new-entity

   generate-model
	  Generate JPA-compliant entity classes from an existing database
	  schema. Uses the Hibernate reverse engineering hbmtemplate task
	  to generate the entity classes. The reverse engineering process
	  can be customized using the resources/seam-gen.reveng.xml file
	  in the project directory.

      Example: seam generate-model

   generate-ui
	  Generate CRUD pages and controllers for existing JPA entity classes.
	  Uses the Hibernate reverse engineering hbmtemplate task to
	  create EntityHome and EntityQuery JavaBean components and
	  Facelet view templates for browsing, searching, and managing the
	  database tables mapped by the entity classes.

      Example: seam generate-ui
	  
   generate
	  Generate CRUD pages and controllers for an existing database
	  schema.  Combines the generate-model and generate-ui commands to
	  create the JPA entity classes and then the pages and controllers
	  that allow them to be managed.

      Example: seam generate

   add-identity-management
     Adds Seam's identity management support to an existing project.  The
     command modifies the component descriptor to activate the identity
     management components, generates annotated User and UserRole entities,
     and wires the identity management components to these entities. The
     command also generates an administrative interface to manage the users
     and roles.

      Example: seam add-identity-management

   add-ivy
     Alters an existing project to use Ivy to manage the dependencies. The
     command adds Ivy configuration files and a corresponding Ant build file.
     The Ant tasks invoke Ivy to download the dependency sets required to
     build, test and deploy the application. The step of downloading the
     dependencies is kept separate from the build life cycle.

      Example: seam add-ivy

albert@athena:~/jboss-seam/jboss-seam-2.3.0.Final$ 

Primer de tot, cal fer el setup del seam-gen, o sigui seam setup

albert@athena:~/jboss-seam/jboss-seam-2.3.0.Final$ seam setup
SEAM_HOME: /home/albert/jboss-seam/jboss-seam-2.3.0.Final
Using seam-gen sources from: /home/albert/jboss-seam/jboss-seam-2.3.0.Final/seam-gen
Buildfile: /home/albert/jboss-seam/jboss-seam-2.3.0.Final/seam-gen/build.xml

init:

setup:
     [echo] Welcome to seam-gen 2.3.0.Final :-)
     [echo] Answer each question or hit ENTER to accept the default (in brackets)
     [echo] 
    [input] Enter the directory where you want the project to be created (should not contain spaces) [/home/albert/projects] [/home/albert/projects]

    [input] Enter your JBoss AS home directory [/home/albert/jboss-seam/jboss-as-7.1.1.Final] [/home/albert/jboss-seam/jboss-as-7.1.1.Final]

    [input] Enter your GlassFish V2 or V3 home directory (Ignore if you aren't deploying to GlassFish) [C:/Program Files/glassfish-v2.1] [C:/Program Files/glassfish-v2.1]

    [input] Enter your GlassFish domain (Ignore if you aren't deploying to GlassFish) [domain1] [domain1]

    [input] Enter the project name [provaseam] [provaseam]

     [echo] Accepted project name as: provaseam
    [input] Select a RichFaces skin [blueSky] ([blueSky], emeraldTown, ruby, classic, japanCherry, wine, deepMarine, DEFAULT, plain)

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

    [input] Enter the base package name for your Java classes [com.mydomain.provaseam] [com.mydomain.provaseam]
com.stsoftlliure.provaseam
    [input] Enter the Java package name for your session beans [com.stsoftlliure.provaseam.action] [com.stsoftlliure.provaseam.action]

    [input] Enter the Java package name for your entity beans [com.stsoftlliure.provaseam.model] [com.stsoftlliure.provaseam.model]

    [input] Enter the Java package name for your test cases [com.stsoftlliure.provaseam.test] [com.stsoftlliure.provaseam.test]

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

    [input] Enter the filesystem path to the JDBC driver jar [/home/albert/mysql-connector-java-5.1.22/mysql-connector-java-5.1.22-bin.jar] [/home/albert/mysql-connector-java-5.1.22/mysql-connector-java-5.1.22-bin.jar]

    [input] skipping input as property driver.license.jar.new has already been set.
    [input] Enter the Hibernate dialect for your database [org.hibernate.dialect.MySQLDialect] [org.hibernate.dialect.MySQLDialect]

    [input] Enter the JDBC driver class for your database [com.mysql.jdbc.Driver] [com.mysql.jdbc.Driver]

    [input] Enter the JDBC DataSource class for your database [com.mysql.jdbc.jdbc2.optional.MysqlDataSource] [com.mysql.jdbc.jdbc2.optional.MysqlDataSource]

    [input] Enter the JDBC URL for your database [jdbc:mysql://localhost/prova_seam] [jdbc:mysql://localhost/prova_seam]

    [input] Enter the database username [root] [root]

    [input] Enter the database password [] []

    [input] skipping input as property hibernate.default_schema.entered has already been set.
    [input] Enter the database catalog name (Enter '-' to clear previous value) [] []

    [input] Are you working with tables that already exist in the database? [y] ([y], n)

    [input] Do you want to recreate the database tables and execute import.sql each time you deploy? [n] (y, [n])

   [delete] Deleting: /home/albert/jboss-seam/jboss-seam-2.3.0.Final/seam-gen/build.properties
[propertyfile] Creating new property file: /home/albert/jboss-seam/jboss-seam-2.3.0.Final/seam-gen/build.properties
     [echo] Installing JDBC driver jar to JBoss AS
     [copy] Copying 1 file to /home/albert/jboss-seam/jboss-as-7.1.1.Final/standalone/deployments

init:

init-properties:
     [echo] /home/albert/jboss-seam/jboss-as-7.1.1.Final

validate-workspace:

validate-project:

settings:
     [echo] JBoss AS home: /home/albert/jboss-seam/jboss-as-7.1.1.Final
     [echo] GlassFish home: C:/Program Files/glassfish-v2.1
     [echo] Project name: provaseam
     [echo] Project location: /home/albert/projects/provaseam
     [echo] Project type: ear
     [echo] IceFaces: ${icefaces.new}
     [echo] Action package: com.stsoftlliure.provaseam.action
     [echo] Model package: com.stsoftlliure.provaseam.model
     [echo] Test package: com.stsoftlliure.provaseam.test
     [echo] JDBC driver class: com.mysql.jdbc.Driver
     [echo] JDBC DataSource class: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
     [echo] Hibernate dialect: org.hibernate.dialect.MySQLDialect
     [echo] JDBC URL: jdbc:mysql://localhost/prova_seam
     [echo] Database username: root
     [echo] Database password: 
     [echo] 
     [echo] Type './seam create-project' to create the new project

BUILD SUCCESSFUL
Total time: 1 minute 48 seconds
albert@athena:~/jboss-seam/jboss-seam-2.3.0.Final$ 

A la carpeta /home/albert/projects encara no s'hi ha creat res. Ho faig ara amb seam create-project:

albert@athena:~/jboss-seam/jboss-seam-2.3.0.Final$ seam create-project
SEAM_HOME: /home/albert/jboss-seam/jboss-seam-2.3.0.Final
Using seam-gen sources from: /home/albert/jboss-seam/jboss-seam-2.3.0.Final/seam-gen
Buildfile: /home/albert/jboss-seam/jboss-seam-2.3.0.Final/seam-gen/build.xml

init:

init-properties:
     [echo] /home/albert/jboss-seam/jboss-as-7.1.1.Final

validate-workspace:

validate-project:

icefaces-staging-copy:

copy-icefaces-home:

copy-icefaces-maven:

copy-lib:
     [echo] Copying Seam and dependencies to the /home/albert/projects/provaseam/lib directory...
     [copy] Copying 317 files to /home/albert/projects/provaseam/lib
     [copy] Copied 5 empty directories to 2 empty directories under /home/albert/projects/provaseam/lib

file-copy-war:

file-copy-ear:
     [echo] Copying build scripts for EAR deployment to the /home/albert/projects/provaseam directory...
     [copy] Copying 2 files to /home/albert/projects/provaseam
     [copy] Copying 1 file to /home/albert/projects/provaseam
     [copy] Copying 1 file to /home/albert/projects/provaseam
     [copy] Copying 1 file to /home/albert/projects/provaseam
     [echo] Copying resources needed for EAR deployment to the /home/albert/projects/provaseam/resources directory...
     [copy] Copying 8 files to /home/albert/projects/provaseam/resources

setup-filters:

file-copy:
     [copy] Copying 1 file to /home/albert/projects/provaseam
     [copy] Copying 3 files to /home/albert/projects/provaseam/resources
     [copy] Copying 13 files to /home/albert/projects/provaseam/resources
     [copy] Copying 4 files to /home/albert/projects/provaseam
     [copy] Copying 1 file to /home/albert/projects/provaseam
     [copy] Copying 1 file to /home/albert/projects/provaseam
     [copy] Copying 1 file to /home/albert/projects/provaseam
     [copy] Copying 1 file to /home/albert/projects/provaseam
     [copy] Copying 1 file to /home/albert/projects/provaseam/.settings
     [copy] Copying 1 file to /home/albert/projects/provaseam
     [copy] Copying 1 file to /home/albert/projects/provaseam
    [mkdir] Created dir: /home/albert/projects/provaseam/nbproject
     [copy] Copying 3 files to /home/albert/projects/provaseam/nbproject
     [copy] Copying 1 file to /home/albert/projects/provaseam/resources
     [copy] Copying 1 file to /home/albert/projects/provaseam/resources
     [copy] Copying 1 file to /home/albert/projects/provaseam/resources
     [copy] Copying 1 file to /home/albert/projects/provaseam/resources
     [copy] Copying 1 file to /home/albert/projects/provaseam/resources
     [copy] Copying 1 file to /home/albert/projects/provaseam/resources
     [copy] Copying 1 file to /home/albert/projects/provaseam/resources
     [copy] Copying 1 file to /home/albert/projects/provaseam/resources
     [copy] Copying 13 files to /home/albert/projects/provaseam/view
     [copy] Copying 16 files to /home/albert/projects/provaseam/view
     [copy] Copying 1 file to /home/albert/projects/provaseam/src/hot/com/stsoftlliure/provaseam/action
     [copy] Copying 1 file to /home/albert/projects/provaseam/src/hot/com/stsoftlliure/provaseam/action
     [copy] Copying 3 files to /home/albert/projects/provaseam
     [copy] Copying 1 file to /home/albert/projects/provaseam
    [mkdir] Created dir: /home/albert/projects/provaseam/src/main/com/stsoftlliure/provaseam/model
    [mkdir] Created dir: /home/albert/projects/provaseam/src/test/com/stsoftlliure/provaseam/test
     [copy] Copying 1 file to /home/albert/projects/provaseam/src/test

create-project:
     [echo] A new Seam project named 'provaseam' was created in the /home/albert/projects directory
     [echo] Type './seam explode' and go to http://localhost:8080/provaseam
     [echo] Eclipse Users: Import the project using File > Import... > Existing Projects into Workspace, set the root directory to /home/albert/projects, then select the project named provaseam
     [echo] NetBeans Users: Open the project using File > Open project... and select the project folder /home/albert/projects/provaseam 
     [echo] IDEA Users: Open the project using File > Open project... and select the file /home/albert/projects/provaseam/provaseam.ipr

BUILD SUCCESSFUL
Total time: 11 seconds
albert@athena:~/jboss-seam/jboss-seam-2.3.0.Final$ 

Fixem-nos que ens indica com importar el projecte a Eclipse, o a NetBeans. El projecte generat és compatible amb aquests dos IDE. Ara podem fer un cop d'ull al projecte generat:

generat

També és interessant examinar la carpeta src. De moment, només hi ha classes per a fer l'autenticació:

src

Continuo, ara genero l'aplicació

albert@athena:~/jboss-seam/jboss-seam-2.3.0.Final$ seam generate
SEAM_HOME: /home/albert/jboss-seam/jboss-seam-2.3.0.Final
Using seam-gen sources from: /home/albert/jboss-seam/jboss-seam-2.3.0.Final/seam-gen
Buildfile: /home/albert/jboss-seam/jboss-seam-2.3.0.Final/seam-gen/build.xml

init:

init-properties:
     [echo] /home/albert/jboss-seam/jboss-as-7.1.1.Final

validate-workspace:

validate-project:

init-generate:

generate-model:
     [echo] Reverse engineering database using JDBC driver /home/albert/mysql-connector-java-5.1.22/mysql-connector-java-5.1.22-bin.jar
     [echo] project=/home/albert/projects/provaseam
     [echo] model=com.stsoftlliure.provaseam.model
[hibernate] Executing Hibernate Tool with a JDBC Configuration (for reverse engineering)
[hibernate] 1. task: hbm2java (Generates a set of .java files)
[hibernate] log4j:WARN No appenders could be found for logger (org.jboss.logging).
[hibernate] log4j:WARN Please initialize the log4j system properly.
[javaformatter] Java formatting of 7 files completed. Skipped 0 file(s).

generate-ui:
     [echo] Building project 'provaseam' to generate views and controllers

init:

groovy.compile:

groovy.copy:

compile:
    [javac] Compiling 7 source files to /home/albert/projects/provaseam/exploded-archives/provaseam.ear/provaseam_jar

copyclasses:

jar:
[hibernate] Executing Hibernate Tool with a JPA Configuration
[hibernate] 1. task: generic exportertemplate: view/list.xhtml.ftl
[hibernate] 2. task: generic exportertemplate: view/view.xhtml.ftl
[hibernate] 3. task: generic exportertemplate: view/view.page.xml.ftl
[hibernate] 4. task: generic exportertemplate: view/edit.xhtml.ftl
[hibernate] 5. task: generic exportertemplate: view/edit.page.xml.ftl
[hibernate] 6. task: generic exportertemplate: src/EntityList.java.ftl
[hibernate] 7. task: generic exportertemplate: view/list.page.xml.ftl
[hibernate] 8. task: generic exportertemplate: src/EntityHome.java.ftl
[hibernate] 9. task: generic exportertemplate: view/layout/menu.xhtml.ftl
[javaformatter] Java formatting of 16 files completed. Skipped 0 file(s).
     [echo] Type './seam restart' and go to http://localhost:8080/provaseam

generate:

BUILD SUCCESSFUL
Total time: 25 seconds
albert@athena:~/jboss-seam/jboss-seam-2.3.0.Final$ 

En aquest moment, si examinem les carpetes del projecte, podrem veure les classes generades d'entitat, les classes Home de les entitats o les classes List. El projecte és a punt per ser desplegat.

Fins aquest punt no m'ha calgut tenir engegat el JBoss AS. Primer de tot, doncs, el poso en marxa (script standalone.sh). Un cop esta en funcionament desplego el driver JDBC de MySQL copiant-lo a la carpeta standalone/deployments. Si estic atent a les traces del servidor, podré veure com el desplega. Puc confirmar-ne el desplegament entrant a la consola d'administració.

Un cop desplegat el driver, faig el deploy.

albert@athena:~/jboss-seam/jboss-seam-2.3.0.Final$ seam deploy
SEAM_HOME: /home/albert/jboss-seam/jboss-seam-2.3.0.Final
Using seam-gen sources from: /home/albert/jboss-seam/jboss-seam-2.3.0.Final/seam-gen
Buildfile: /home/albert/jboss-seam/jboss-seam-2.3.0.Final/seam-gen/build.xml

init:

init-properties:
     [echo] /home/albert/jboss-seam/jboss-as-7.1.1.Final

validate-workspace:

validate-project:

deploy:
     [echo] Deploying project 'provaseam' to JBoss AS

init:

clear-profile-artifacts:
   [delete] Deleting: /home/albert/projects/provaseam/exploded-archives/provaseam.ear/provaseam_jar/META-INF/persistence.xml
   [delete] Deleting: /home/albert/projects/provaseam/exploded-archives/provaseam.ear/provaseam_jar/import.sql
   [delete] Deleting: /home/albert/projects/provaseam/exploded-archives/provaseam.ear/provaseam_war/WEB-INF/classes/components.properties

groovy.compile:

groovy.copy:

compile:

copyclasses:

jar:
     [copy] Copying 1 file to /home/albert/projects/provaseam/exploded-archives/provaseam.ear/provaseam_jar/META-INF
     [copy] Copying 1 file to /home/albert/projects/provaseam/exploded-archives/provaseam.ear/provaseam_jar

war:
     [copy] Copying 1 file to /home/albert/projects/provaseam/exploded-archives/provaseam.ear/provaseam_war/WEB-INF/classes

ear:

stage:

archive:
      [jar] Building jar: /home/albert/projects/provaseam/dist/provaseam.jar
      [jar] Building jar: /home/albert/projects/provaseam/dist/provaseam.war
      [jar] Building jar: /home/albert/projects/provaseam/dist/provaseam.ear

datasource:
     [copy] Copying 1 file to /home/albert/jboss-seam/jboss-as-7.1.1.Final/standalone/deployments

deploy:
     [copy] Copying 1 file to /home/albert/jboss-seam/jboss-as-7.1.1.Final/standalone/deployments

BUILD SUCCESSFUL
Total time: 18 seconds
albert@athena:~/jboss-seam/jboss-seam-2.3.0.Final$ 

A les traces del servidor hi puc veure com, efectivament, s'ha desplegat l'aplicació

19:19:03,572 INFO  [org.jboss.web] (MSC service thread 1-2) JBAS018210: Registering web context: /provaseam
19:19:03,843 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "provaseam.ear"
19:19:03,848 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "provaseam-ds.xml"

Ara ja puc provar l'aplicació tot just desplegada. Apunto el navegador a http://localhost:8080/provaseam i ja puc fer servir la meva aplicació de biblioteca.

La pàgina de benvinguda a l'aplicació:

provaseam1

EL browser de les taules, que ens permet accedir al manteniment de cadascuna d'elles:

provaseam2

La pantalla de login. No ens permetrà fer inserts si no estem "logats".

provaseam3

I la pàgina de llibres:

provaseam4

O la de formats:

provaseam5

Com amb Seam 3.1.0, el resultat és força espectacular. Val a dir que en executar l'aplicació m'he trobat amb alguns problemes amb els ID dels objectes que cal revisar. També s'ha de remarcar la mida força important que pren l'ear i que està relacionada amb la quantitat de llibreries que incorpora el framework. En una aplicació tan senzilla com aquesta, no en faig servir gairebé cap i és una despesa d'espai important.

El que és interessant de debò és el joc subterrani. Amb les classes d'entitat generades, les classes home/list i la generació de les vistes amb les RichFaces. És el que de debò cal conèixer. És el que permetrà afinar una aplicació generada pel broc gros on, segurament, hi ha més del que ens cal, i no tot el que voldríem.

En resum, un exemple de generació ràpida d'aplicacions CRUD per a entorns Java EE amb Framewrok Seam 2.3.0.

Una eina més al sarró.