<meta content="text/html; charset=utf-8" http-equiv="CONTENT-TYPE"><meta name="GENERATOR" content="OpenOffice.org 2.4 (Win32)"><style type="text/css">
</style>
Building
Seam 2.0 Application with NetBeans 6.1
转载请保留作者信息:
Author:
88250
Blog:
http:/blog.csdn.net/DL88250
MSN
& Gmail & QQ: DL88250@gmail.com
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
:-)
<meta content="text/html; charset=utf-8" http-equiv="CONTENT-TYPE"><meta name="GENERATOR" content="OpenOffice.org 2.4 (Win32)"><style type="text/css">
<!----></style><meta content="text/html; charset=utf-8" http-equiv="CONTENT-TYPE"><meta name="GENERATOR" content="OpenOffice.org 2.4 (Win32)"><style type="text/css">
<!---->
</style>
<meta content="text/html; charset=utf-8" http-equiv="CONTENT-TYPE"><meta name="GENERATOR" content="OpenOffice.org 2.4 (Win32)"><style type="text/css">
<!---->
</style>
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
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:
<?xml
version="1.0" encoding="UTF-8"?>
<application
version="5" 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/application_5.xsd">
<display-name>HelloSeam</display-name>
<module>
<web>
<web-uri>HelloSeam-war.war</web-uri>
<context-root>/HelloSeam-war</context-root>
</web>
</module>
<module>
<ejb>HelloSeam-ejb.jar</ejb>
</module>
</application>
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:
<?xml
version="1.0" encoding="UTF-8"?>
<ejb-jar
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/ejb-jar_3_0.xsd"
version="3.0">
<interceptors>
<interceptor>
<interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class>
</interceptor>
</interceptors>
<assembly-descriptor>
<interceptor-binding>
<ejb-name>*</ejb-name>
<interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class>
</interceptor-binding>
</assembly-descriptor>
</ejb-jar>
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:
<?xml
version="1.0" encoding="UTF-8"?>
<persistence
version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit
name="userDatabase">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/seamHelloDS</jta-data-source>
<class>org.jboss.seam.example.registration.User</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<!--
The following two properties are for Glassfish -->
<property
name="hibernate.dialect"
value="org.hibernate.dialect.DerbyDialect"/>
<property
name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.SunONETransactionManagerLookup"/>
<!--
common configurations -->
<property
name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property
name="hibernate.show_sql" value="true"/>
<property
name="hibernate.transaction.flush_before_completion"
value="true"/>
<property
name="hibernate.cache.provider_class"
value="org.hibernate.cache.HashtableCacheProvider"/>
</properties>
</persistence-unit>
</persistence>
Notice:
This demonstration
use Hibernate as the JPA provider.
Create the seam.properties
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
Create the compoonents.xml
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:
<?xml
version="1.0" encoding="UTF-8"?>
<components
xmlns="http://jboss.com/products/seam/components"
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">
<core:init
jndi-pattern="java:comp/env/HelloSeam/#{ejbName}/local" />
<!-- some
issue with ejb transcation using glassfish v2, also comments
web.xml
-->
<!--
<transaction:ejb-transaction/>
-->
<core:manager
conversation-timeout="120000"
concurrent-request-timeout="500"
conversation-id-parameter="cid"/>
</components>
Notice:
formerly, I want to use
ejb transaction
for JPA, but there is some issues
working with Glassfish v2....
Create the faces-config.xml
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:
<?xml
version="1.0" encoding="UTF-8"?>
<faces-config
version="1.2"
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">
<!-- Facelets
support -->
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
</faces-config>
Notice:
I defines the navigation rules
in file pages.xml, as JBoss Seam recommend, refers to the next
instruction.
Create
the pages.xml
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:
<?xml
version="1.0" encoding="UTF-8"?>
<pages
xmlns="http://jboss.com/products/seam/pages"
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"
>
<page
view-id="/register.xhtml">
<navigation>
<rule
if="#{register.registered}">
<redirect
view-id="/registered.xhtml"/>
</rule>
</navigation>
</page>
<exception
class="org.jboss.seam.security.NotLoggedInException">
<redirect
view-id="/.xhtml">
<message
severity="warn">You must be logged in to use this
feature
</message>
</redirect>
</exception>
</pages>
Create
the web.xml
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:
<?xml
version="1.0" encoding="UTF-8"?>
<web-app
version="2.5" 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-app_2_5.xsd">
<!-- Seam -->
<listener>
<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
</listener>
<filter>
<filter-name>Seam
Filter</filter-name>
<filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Seam
Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>Seam
Resource Servlet</servlet-name>
<servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Seam
Resource Servlet</servlet-name>
<url-pattern>/seam/resource/*</url-pattern>
</servlet-mapping>
<!-- JSF and
Facelets -->
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
分享到:
相关推荐
【JBoss Seam 2.0文档详解】 JBoss Seam 是一个开源的企业级开发框架,它旨在简化Java EE应用的开发过程,特别是在Web和富互联网应用程序(Rich Internet Applications, RIA)领域。Seam 2.0是其重要的版本,提供了...
从给定的文件信息来看,这是一份关于Seam2.0的技术文档,尽管部分文本似乎是乱码,但我们可以从其结构和部分可识别的文字中提取出与Seam2.0相关的关键知识点。 ### Seam2.0概述 Seam2.0是一个基于Java的框架,用于...
1. 配置环境:安装JBoss Application Server,设置开发工具(如Eclipse或NetBeans)的Seam插件。 2. 创建项目:使用Seam生成器创建新项目,定义组件、事件和依赖关系。 3. 编写组件:编写JSF组件、EJB3实体或...
在"seam2.0 全国 省份、城市级联"这个项目中,我们主要关注的是如何利用Seam 2.0实现一个全国省份和城市之间的二级联动效果。 级联选择通常用于网页表单中,允许用户首先选择一个省份,然后根据所选省份动态加载...
通过深入学习和理解"seam2.0 中文文档",开发者可以充分利用Seam 2.0 的强大功能,高效地开发出复杂的企业级应用。这份文档是学习和使用Seam 2.0 的宝贵资源,可以帮助开发者快速上手并掌握关键概念。
Seam 2.0 是一个全面的Java EE框架,它为开发富互联网应用程序(RIA)提供了强大的工具和支持。这个框架整合了多种技术,如JSF、EJB、CDI、Hibernate等,使得开发者能够更轻松地处理上下文、会话管理、组件以及企业...
**JBoss Seam 2.0:语境相关的组件** JBoss Seam 2.0 是一个开源的Java EE框架,它将企业级服务与富互联网应用(RIA)开发紧密结合,简化了构建复杂Web应用的过程。Seam的核心特性之一是其对上下文(Contexts)和...
### Seam2.0 GA 中文开发指南 #### JBoss Seam简介 JBoss Seam是一个高度集成的应用框架,旨在简化企业级Java应用的开发过程。Seam2.0版本提供了丰富的功能来支持面向组件的编程模式,并且它紧密集成了JavaServer ...
seam2.0_api帮助文件,chm文件
整理自jboss seam 中文站,压缩为chm格式,便于广大jboss seam爱好者阅读,所有版权归jboss seam中文站所有。
Seam 2.0 是一个全面的Java EE框架,它为开发人员提供了一种整合多种技术,如JavaServer Faces (JSF)、Enterprise JavaBeans (EJB)、Java Persistence API (JPA)以及Spring等的强大工具。这个"Seam_2.0_Reference_zh...
根据提供的文件信息,我们可以推断出这是一份关于Seam 2.0的中文参考文档。Seam是一个基于Java EE平台的应用程序框架,它集成了JSF、EJB和其他技术来简化企业级应用的开发过程。下面将从几个方面详细阐述Seam 2.0中...
Seam 2.0_R中文手册则聚焦于Seam框架,这是一个整合了JSF(JavaServer Faces)、EJB 3、JPA(Java Persistence API)等技术的全栈式框架。Seam的目标是提供一个无缝的开发环境,让开发者能够轻松地构建富互联网应用...
Jboss_Seam_2.0中文手册
### Seam Framework 2.0 Reference中文版知识点梳理 #### JBoss Seam 概述 JBoss Seam 是一款基于 Java 的企业级应用开发框架,它简化了应用程序的开发过程,特别是那些涉及复杂的用户交互、业务逻辑以及数据处理的...
2. **CDI支持**: 虽然Seam 2.0发布时,Contexts and Dependency Injection (CDI)规范还未正式发布,但Seam已经提供了类似的功能。 3. **Seam生成器(Seam Generator)**: 提供了一套工具,用于快速生成Seam项目和...
Seam - 语境相关的组件 [满江红20080327] Java EE框架
在开始开发前,确保已经安装了Java Development Kit (JDK)、NetBeans IDE以及jBoss AS (Application Server)。NetBeans通常会提供内置的jBoss AS版本,但也可以选择手动安装。 2. **设置NetBeans**: 打开...