JBoss Seam is a widespread framework for rapid development of applications with JavaEE 5. It provides a neat wrapper around JSF and EJB that removes most of the "glue code" prevalent in many JSF applications that use EJB. Main features include a close integration of EJB persistence (JPA), a conversation scope for JSF, or business process management via jBPM.
This chapter is a quick guide to integrating [fleXive] into an existing Seam application.
To integrate [fleXive] with Seam, you need to
modify your build file to add the [fleXive] libraries to the packages EAR file, and
modify your
web.xml
and
application.xml
deployment descriptors.
Both tasks shouldn't take you more than a few minutes, and both are easy to undo.
First of all, you need unpack a [fleXive] distribution as described in Chapter 4, Writing [fleXive] applications . You don't need to actually start [fleXive], but you need access to the distribution directory.
When you have a local [fleXive] distribution installed, go to you Seam project directory and perform the following tasks:
Modify your
build.xml
:
[fleXive] will copy all required libraries to the
exploded-archives
folder every time your application is built.
Include
build.seam-project.xml
at the top of
build.xml
.
FLEXIVE-DIST
is the path to your local [fleXive] distribution.
<project name="myseamproject" default="deploy" basedir="."> <import file="FLEXIVE-DIST/build.seam-project.xml"/>
Add a dependency for
copyflexive
to the
archive
target:
<target name="archive" depends="jar,war,ear,copyflexive" description="Package the archives">
To check if everything still works, you should build and deploy your application now.
Add a reference to
flexive-ejb.jar
to
resources/META-INF/application.xml
:
<!-- Flexive EJBs --> <module> <ejb>flexive-ejb.jar</ejb> </module>
Add the [fleXive] filter and the Weblets listener to
resources/WEB-INF/web.xml
:
<filter> <filter-name>FlexFilter</filter-name> <filter-class>com.flexive.war.filter.FxFilter</filter-class> </filter> <filter-mapping> <filter-name>FlexFilter</filter-name> <url-pattern>*.seam</url-pattern> </filter-mapping> <listener> <listener-class>net.java.dev.weblets.WebletsContextListener</listener-class> </listener>
The
FlexFilter
is needed to provide the [fleXive] context (e.g. the current user ticket)
for every request, and Weblets is used to serve Javascript and CSS files needed by
the JSF components.
Add a suffix pattern for the
Faces Servlet
as the
last
servlet mapping to
resources/WEB-INF/web.xml
.
Otherwise all Weblets resources will have a
.seam
suffix instead of the original file extension.
<servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.seam</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>/faces/*</url-pattern> </servlet-mapping>
To test if the [fleXive] integration was sucessful, add the following code snippet to one of your front-end pages:
#{fxSystemBean.buildInfoVerbose}
It should render the [fleXive] version and build number. If no text is rendered, please check the logfile for error messages during the application startup. [fleXive] writes several status log messages on application startup, so you should see at least some messages originating from [fleXive].
When using [fleXive] UI tags on your pages, be sure to declare the
fx
namespace in your XHTML root element:
xmlns:fx="http://www.flexive.com/jsf/core"