Chapter 24. Remoting

Seam uses Asynchronous JavaScript and XML (AJAX) to remotely access components from a web page. The framework for this functionality requires very little development effort — you can make your components AJAX-accessible with simple annotations. This chapter describes the steps required to build an AJAX-enabled web page, and explains the Seam Remoting framework in further detail.

24.1. Configuration

To use remoting, you must first configure your Seam Resource Servlet in your web.xml file:
<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>
Next, import the necessary JavaScript into your web page. A minimum of two scripts must be imported. The first contains all client-side framework code, which enables remoting functionality:
<script type="text/javascript" 
        src="seam/resource/remoting/resource/remote.js">
</script>
The second contains the stubs and type definitions for the components you wish to call. This is generated dynamically, based on the local interface of your components, and includes type definitions for all classes that can be used to call the remotable methods of the interface. The script name reflects your component name. For example, if you annotate a stateless session bean with @Name("customerAction"), your script tag should look like this:
<script type="text/javascript" 
        src="seam/resource/remoting/interface.js?customerAction">
</script>
If you want to access more than one component from the same page, include them all as parameters of your script tag:
<script type="text/javascript" 
        src="seam/resource/remoting/interface.js?customerAction&accountAction">
</script>
You can also use the s:remote tag to import the required JavaScript. Separate each component or class name that you want to import with a comma:
<s:remote include="customerAction,accountAction"/>