Configuring Seam with JSF

The official JBoss Seam home page describes Seam as follows:

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.

As you can see, JBoss Seam provides support for JSF (1.2 and 2.0), and in this recipe you will see what are the main configurations that should be accomplished for integrating these two powerful technologies.

Getting ready

The JBoss Seam distribution can be downloaded from http://seamframework.org/.

How to do it...

Supposing that you already have the JBoss Seam and JSF libraries, then you can integrate Seam with JSF and your servlet container by adding a few entries to the web.xml and faces-config.xml descriptors. It should be done as shown:

  1. Add a listener that is responsible for bootstrapping Seam, and for destroying session and application contexts. This can be added as:
    …
    <listener>
    <listener-class>org.jboss.seam.servlet.SeamListener
    </listener-class>
    </listener>
    …
    
  2. You need a JSF PhaseListener registered in the faces-config.xml file:
    …
    <lifecycle>
    <phase-listener>
    org.jboss.seam.jsf.SeamPhaseListener
    </phase-listener>
    </lifecycle>
    …
    
  3. If you are using JSF 1.2 then you should also add this to faces-config.xml:
    …
    <application>
    <el-resolver>org.jboss.seam.jsf.SeamELResolver</el-resolver>
    </application>
    …
    

    Note

    Some JSF implementations have a broken implementation of server-side state saving that interferes with Seam's conversation propagation. You can fix this by adding the following parameter to web.xml:

    …
    <context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
    </context-param>
    …
    

There's more...

The previous configurations provide the minimum support required for integrating JSF and Seam. Depending on your application's complexity you may need more configurations.

Configuring Seam Resource Servlet

Seam Resource Servlet provides resources used by Seam Remoting, captchas, and some JSF UI controls. The following web.xml entry configures this servlet:

…
<servlet>
<servlet-name>Seam Resource Servlet</servlet-name>
<servlet-class>
org.jboss.seam.servlet.ResourceServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Seam Resource Servlet</servlet-name>
<url-pattern>/seam/resource/*</url-pattern>
</servlet-mapping>
…

Configuring Seam servlet filters

Seam lets you add and configure servlet filters exactly as you would configure other built-in Seam components. For this you must first install a master filter in web.xml:

…
<filter>
<filter-name>Seam Filter</filter-name>
<filter-class>org.jboss.seam.web.SeamFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Seam Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
…

Multipart form submissions

The following entry detects multipart form requests and processes them according to the multipart/form-data specification (RFC-2388). To override the default settings, add the following entry to components.xml:

…
<web:multipart-filter create-temp-files="true"
max-request-size="1000000"
url-pattern="*.seam"/>
…
  • create-temp-files: If this is set to true, uploaded files are written to a temporary file (instead of being held in memory). The default is false.
  • max-request-size: indicates the maximum size of the file upload. The default setting is 0 (no size limit).
  • url-pattern: used to specify which requests are filtered; the default is all requests.

Setting the character encoding

Setting the character encoding of submitted form data can be accomplished by adding the following entry to the component.xml descriptor:

…
<web:character-encoding-filter encoding="UTF-16"
override-client="true"
url-pattern="*.seam"/>
…
  • encoding: The encoding to use.
  • override-client: If this is set to true, the request encoding will be set to whatever is specified by encoding no matter whether the request already specifies an encoding or not. If it is set to false, the request encoding will only be set if the request does not already specify an encoding. By default it is false.
  • url-pattern: Used to specify which requests are filtered; the default is all requests.

Conversation propagation with redirects

This filter allows Seam to propagate the conversation context across browser redirects. It intercepts any browser redirects and adds a request parameter that specifies the Seam conversation identifier. The behavior of this filter is adjusted in components.xml:

…
<web:redirect-filter url-pattern="*.seam"/>
…
  • url-pattern: Used to specify which requests are filtered; the default is all requests.

Exception handling

By default, the exception handling filter will process all requests; however, this behavior may be adjusted by adding a <web:exception-filter> entry to components.xml, as shown:

…
<components xmlns="http://jboss.com/products/seam/components"
xmlns:core="http://jboss.com/products/seam/core"
xmlns:web="http://jboss.com/products/seam/web"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.com/products/seam/core
http://jboss.com/products/seam/core-1.2.xsd
http://jboss.com/products/seam/components
http://jboss.com/products/seam/components-1.2.xsd
http://jboss.com/products/seam/web
http://jboss.com/products/seam/web-1.2.xsd">
<web:exception-filter url-pattern="*.seam"/>
</components>
…
  • url-pattern: Used to specify which requests are filtered; the default is all requests.

See also

More details about configuring Seam and JSF can be found at:

http://docs.jboss.org/seam/1.2.1.GA/reference/en/html/

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset