Building Seam 2.0 Application with NetBeans 6.1
转载请保留作者信息:
Author: 88250
Blog: http:/blog.csdn.net/DL88250
MSN & Gmail & QQ: [email protected]
Table of Contents
Introduction 1
Prerequisites 2
Seam glimpse 2
Set up HelloSeam application 2
Create Project 2
Create a enterprise application deployment descriptor 2
Add dependencies for HelloSeam-ejb project 3
Add dependencies for HelloSeam-war project 3
Create a ejb deployment descriptor 3
Create a persistence unit of ejb project 4
Create the seam.properties 4
Create the compoonents.xml 5
Create the faces-config.xml 5
Create the pages.xml 5
Create the web.xml 6
Web pages coding 7
EJB Benas coding 9
The End.... 11
References: 11
Introduction
This article depicts how to build a simple registration application base on JBoss Seam 2.0(JSF with Facelets, EJB3, JPA) using NetBeans 6.1, and deploys it on Glassfish v2, MySQL 5.1.
To the demonstration building, I divide the its content into two ways:
Using NetBeans built-in project wizard to create a enterprise application, which includes a ejb project and a web project. This entry will use this way to build the sample application.
Using Maven for NetBeans plugin to create a enterprise application, also it includes a ejb project and a web project. This way I will use to the subsequent entry, please pay more attention to my blog: http://blog.csdn.net/DL88250 :-)
All of these, will deploy on Glassfish V2 and use MySQL 5.1 community edition. As I mentioned formerly, this demo using Facelets framework for JSF view definition, the most important thing is it setup with NetBeans IDE project wizard and deploys on Glassfish v2. Although you maybe refer to jee-booking example in JBoss Seam tutorial, there are some practical issues you will occur. So, Just follow me! :-)
Prerequisites
JavaEE Programming(JSF, EJB3, JPA)
Usage of NetBeans IDE 6.1
JBoss Seam Framework 2.0
Facelets
In this sample application, I use Facelets as JSF view definition framework, it is a very elegant presentation for JSF.
Seam glimpse
As we known, Seam is a powerful open source development platform for building rich Internet applications in Java. Seam integrates technologies such as Asynchronous JavaScript and XML (AJAX), JavaServer Faces (JSF), Java Persistence (JPA), Enterprise Java Beans (EJB 3.0) and Business Process Management (BPM) into a unified full-stack solution, complete with sophisticated tooling. The simple chart of architectural design will show you about this:
The following demonstration will show you a part of features Seam brought.
Set up HelloSeam application
In this section, I will mention some important notices of creating seam application using NetBeans IDE.
Create Project
Open NetBeans IDE, and create a enterprise application project, named HelloSeam. It should include a ejb application project(HelloSeam-ejb) and a web application project(HelloSeam-war).
Create a enterprise application deployment descriptor
The descriptor named application.xml, is placed in HelloSeam/src/conf/, when we build project, it will copy to HelloSeam/dist/HelloSeam.ear/META-INF. Its content like this:
Notice: add the jboss-seam.jar as a ejb module is NOT necessary.
Add dependencies for HelloSeam-ejb project
Open you HelloSeam-ejb project, add the following jar libraries:
All of them you can find under SeamHome/lib.
Add dependencies for HelloSeam-war project
All of them you can find under SeamHome/lib or under FaceletsHome.
Create a ejb deployment descriptor
The descriptor named ejb-jar.xml, is placed in HelloSeam-ejb/src/conf/, when we build project, it will copy to HelloSeam-ejb/dist/HelloSeam-ejb.jar/META-INF. Its content like this:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" version="3.0">
Create a persistence unit of ejb project
The descriptor named persistence.xml, is placed in HelloSeam-ejb/src/conf/, when we build project, it will copy to HelloSeam-ejb/dist/HelloSeam-ejb.jar/META-INF. Its content like this:
value="org.hibernate.dialect.DerbyDialect"/> value="org.hibernate.transaction.SunONETransactionManagerLookup"/> value="org.hibernate.cache.HashtableCacheProvider"/> Notice: This demonstration use Hibernate as the JPA provider. Create a file named seam.properties, and places it in HelloSeam-ejb/src/conf/. This file is very important for loading seam components. If you ignores it, maybe you will occurs some particular exceptions, such as follow: javax.el.PropertyNotFoundException: /register.xhtml @17,90 value="#{user.username}": Target Unreachable, identifier 'user' resolved to null The descriptor named components.xml, is placed in HelloSeam-war/web/WEB-INF/, when we build project, it will copy to HelloSeam-war/dist/HelloSeam-war.war/WEB-INF. Its content like this: xmlns:core="http://jboss.com/products/seam/core" xmlns:security="http://jboss.com/products/seam/security" xmlns:transaction="http://jboss.com/products/seam/transaction" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.0.xsd http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd"> concurrent-request-timeout="500" conversation-id-parameter="cid"/> Notice: formerly, I want to use ejb transaction for JPA, but there is some issues working with Glassfish v2.... The descriptor named faces-config.xml, is placed in HelloSeam-war/web/WEB-INF/, when we build project, it will copy to HelloSeam-war/dist/HelloSeam-war.war/WEB-INF. Its content like this: xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"> Notice: I defines the navigation rules in file pages.xml, as JBoss Seam recommend, refers to the next instruction. The descriptor named pages.xml, is placed in HelloSeam-war/web/WEB-INF/, when we build project, it will copy to HelloSeam-war/dist/HelloSeam-war.war/WEB-INF. Its content like this: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.0.xsd" > The descriptor named web.xml, is placed in HelloSeam-war/web/WEB-INF/, when we build project, it will copy to HelloSeam-war/dist/HelloSeam-war.war/WEB-INF. Its content like this:
Create the seam.properties
Create the compoonents.xml
Create the faces-config.xml
Create the pages.xml
Create the web.xml