org.directwebremoting.spring
Class DwrController

java.lang.Object
  extended by org.springframework.context.support.ApplicationObjectSupport
      extended by org.springframework.web.context.support.WebApplicationObjectSupport
          extended by org.springframework.web.servlet.support.WebContentGenerator
              extended by org.springframework.web.servlet.mvc.AbstractController
                  extended by org.directwebremoting.spring.DwrController
All Implemented Interfaces:
org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.web.context.ServletContextAware, org.springframework.web.servlet.mvc.Controller

public class DwrController
extends org.springframework.web.servlet.mvc.AbstractController
implements org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.BeanFactoryAware

A Spring Controller that handles DWR requests.
Using this controller allows you to configure DWR entirely in Spring. You do not have to create a separate dwr.xml configuration file when using this controller.

The following configuration provides a basic example of how too define this controller as a bean in your application context.

   <bean id="dwrController" class="org.directwebremoting.spring.DwrController">
      <property name="configurators">
         <list>
            <ref bean="dwrConfiguration"/>
         </list>
      </property>
      <property name="debug" value="true"/>
   </bean>

   <bean id="dwrConfiguration" class="org.directwebremoting.spring.SpringConfigurator">
      <property name="creators">
         <map>
            <entry key="mybean">
               <bean class="org.directwebremoting.spring.CreatorConfig">
                  <property name="creator">
                     <bean class="org.directwebremoting.spring.BeanCreator">
                        <property name="bean" ref="myBean"/>
                     </bean>
                  </property>
               </bean>
            </entry>
         </map>
      </property>
   </bean>

   <-- the bean you want to remote using DWR -->
   <bean id="myBean" class="MyBean"/>
   
In the near future we want to provide a DWR namespace for Spring, which should allow you to something like the following:
   <dwr:configuration>
      <debug/>
   </dwr:configuration>

   <-- the bean you want to remote using DWR -->
   <bean id="myBean" class="MyBean">
      <dwr:remote javascript="mybean"/>
   </bean>
   
Which should be equivalent to the previous example. Please note that this is still work in progress and is therefore subject to change.

Author:
Joe Walker [joe at getahead dot ltd dot uk], Bram Smeets

Field Summary
protected  WebContextFactory.WebContextBuilder webContextBuilder
          The builder for the WebContext that keeps http objects local to a thread
 
Fields inherited from class org.springframework.web.servlet.support.WebContentGenerator
METHOD_GET, METHOD_HEAD, METHOD_POST
 
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
 
Constructor Summary
DwrController()
           
 
Method Summary
 void afterPropertiesSet()
          Is called by the Spring container after all properties have been set.
protected  org.springframework.web.servlet.ModelAndView handleRequestInternal(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Handles all request to this controller.
 void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
          Is called by the Spring container to set the bean factory.
 void setBeanName(java.lang.String name)
          Is called by the Spring container to set the name of this bean.
 void setConfigParams(java.util.Map configParams)
          Additional parameters such as pollAndCometEnabled.
 void setConfigurators(java.util.List configurators)
          Sets the configurators to apply to this controller.
 void setDebug(boolean debug)
          Sets whether DWR should be in debug mode (default is false).
 void setIncludeDefaultConfig(boolean includeDefaultConfig)
          Sets whether the default DWR configuration should be included (default is true).
 
Methods inherited from class org.springframework.web.servlet.mvc.AbstractController
handleRequest, isSynchronizeOnSession, setSynchronizeOnSession
 
Methods inherited from class org.springframework.web.servlet.support.WebContentGenerator
applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, getCacheSeconds, getSupportedMethods, isRequireSession, isUseCacheControlHeader, isUseExpiresHeader, preventCaching, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseExpiresHeader
 
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, isContextRequired, setServletContext
 
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

webContextBuilder

protected WebContextFactory.WebContextBuilder webContextBuilder
The builder for the WebContext that keeps http objects local to a thread

See Also:
WebContext
Constructor Detail

DwrController

public DwrController()
Method Detail

setBeanFactory

public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory)
                    throws org.springframework.beans.BeansException
Is called by the Spring container to set the bean factory.
This bean factory is then used to obtain the global DWR configuration from. This global configuration is optional as DWR will provide defaults where possible.

Specified by:
setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
Throws:
org.springframework.beans.BeansException
See Also:
BeanFactoryAware.setBeanFactory(org.springframework.beans.factory.BeanFactory)

setDebug

public void setDebug(boolean debug)
Sets whether DWR should be in debug mode (default is false).
This allows access to the debug pages provided by DWR under /[app-ctx]/dwr/. NOTE: make sure to not set this property to true in a production environment.

Parameters:
debug - the indication of whether to start DWR in debug mode

setConfigurators

public void setConfigurators(java.util.List configurators)
Sets the configurators to apply to this controller.
The configurators are used to set up DWR correctly.

Parameters:
configurators - the configurators to apply to this controller

setIncludeDefaultConfig

public void setIncludeDefaultConfig(boolean includeDefaultConfig)
Sets whether the default DWR configuration should be included (default is true).
This default configuration contains all build-in creators and converters. You normally want this default configuration to be included.

Parameters:
includeDefaultConfig - the indication of whether to include the default configuration

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.lang.Exception
Is called by the Spring container after all properties have been set.
This method actually makes sure the container is correctly initialized and all configurators are processed.

Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
java.lang.Exception - in case setting up fails
See Also:
InitializingBean.afterPropertiesSet()

handleRequestInternal

protected org.springframework.web.servlet.ModelAndView handleRequestInternal(javax.servlet.http.HttpServletRequest request,
                                                                             javax.servlet.http.HttpServletResponse response)
                                                                      throws java.lang.Exception
Handles all request to this controller.
It delegates to the UrlProcessor and also takes case of setting and unsetting of the current WebContext.

Specified by:
handleRequestInternal in class org.springframework.web.servlet.mvc.AbstractController
Parameters:
request - the request to handle
response - the reponse to handle
Throws:
java.lang.Exception - in case handling of the request fails unexpectedly
See Also:
WebContext

setBeanName

public void setBeanName(java.lang.String name)
Is called by the Spring container to set the name of this bean.

Specified by:
setBeanName in interface org.springframework.beans.factory.BeanNameAware
Parameters:
name - the name of this bean in the Spring container
See Also:
BeanNameAware.setBeanName(String)

setConfigParams

public void setConfigParams(java.util.Map configParams)
Additional parameters such as pollAndCometEnabled. For a full list see: http://getahead.org/dwr/server/servlet

Parameters:
configParams - the configParams to set


Copyright © 2007. All Rights Reserved.