Quick-Start: SEAM-Framework and Maven without seam-gen

Frank

This short tutorial gives you the needed steps to integrate SEAM into an existing WAR-project or to build such a WAR from the beginning.

1. Including Dependencies

First of all you need to add the SEAM dependencies and of course JSF, if not already present:

		<dependency>
			<groupId>javax.faces</groupId>
			<artifactId>jsf-api</artifactId>
			<version>1.2_15</version>
		</dependency>
		<dependency>
			<groupId>javax.faces</groupId>
			<artifactId>jsf-impl</artifactId>
			<version>1.2_15</version>
		</dependency>
		<dependency>
			<groupId>com.sun.facelets</groupId>
			<artifactId>jsf-facelets</artifactId>
			<version>1.1.15.B1</version>
		</dependency>
		<dependency>
			<groupId>org.jboss.seam</groupId>
			<artifactId>jboss-seam</artifactId>
			<version>2.2.1.Final</version>
			<exclusions>
				<exclusion>
					<groupId>javax.el</groupId>
					<artifactId>el-api</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.jboss.seam</groupId>
			<artifactId>jboss-seam-ui</artifactId>
			<version>2.2.1.Final</version>
		</dependency>

2. Modify web.xml

Here you have to add the FacesServlet for JSF, the Seam-Filter for SEAM and a Listener for SEAM. Additionally you can define some CONTEXT-variables for JSF / SEAM.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	version="2.5">
	<!-- Context Variables -->
	<context-param>
		<param-name>facelets.SKIP_COMMENTS</param-name>
		<param-value>true</param-value>
	</context-param>
	<!-- Seam Listener -->
	<listener>
		<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
	</listener>
	<!-- Seam Filter -->
	<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>
	<!-- JSF Servlet -->
	<servlet>
		<servlet-name>Faces Servlet</servlet-name>
		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>Faces Servlet</servlet-name>
		<url-pattern>*.html</url-pattern>
	</servlet-mapping>
	<!-- Seam Resource Servlet -->
	<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>
</web-app>

3. Configure JSF

Then you have to add an faces-config.xml to the WEB-INF directory.

<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xi="http://www.w3.org/2001/XInclude"
 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">
</faces-config>

4. Configure SEAM
Just add some empty configuration files to enable seam for your WAR.

<?xml version="1.0" encoding="UTF-8"?>
<components xmlns="http://jboss.com/products/seam/components"
	xmlns:core="http://jboss.com/products/seam/core" xmlns:transaction="http://jboss.com/products/seam/transaction"
	xmlns:web="http://jboss.com/products/seam/web" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<core:init debug="false" />
</components>

And also put an empty seam.properties to your classpath (in directory src/main/resources).


2 Responses to “Quick-Start: SEAM-Framework and Maven without seam-gen”

  • Patrick Dumontel Says:

    Interesting. Is there anyway these could be created via an archetype?

    • Frank Says:

      I don’t know a free archetype. This is in detail a difficult problem, because you maybe have a JBoss Environment and want also EJB3 or you only have a Tomcat environment and only want to use SEAM in the presentation layer.

Leave a Reply