org.codehaus.groovy.grails.plugins.web.api
Class ControllersApi

java.lang.Object
  extended by org.codehaus.groovy.grails.plugins.web.api.CommonWebApi
      extended by org.codehaus.groovy.grails.plugins.web.api.ControllersApi
All Implemented Interfaces:
java.io.Serializable, org.codehaus.groovy.grails.plugins.support.aware.GrailsApplicationAware, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, org.springframework.web.context.ServletContextAware

public class ControllersApi
extends org.codehaus.groovy.grails.plugins.web.api.CommonWebApi

API for each controller in a Grails application.

Since:
2.0
See Also:
Serialized Form

Field Summary
protected static java.lang.String BIND_DATA_METHOD
           
protected  org.codehaus.groovy.grails.web.metaclass.ForwardMethod forwardMethod
           
protected  RedirectDynamicMethod redirect
           
protected  RenderDynamicMethod render
           
protected static java.lang.String RENDER_METHOD_NAME
           
protected static java.lang.String SLASH
           
protected  org.codehaus.groovy.grails.web.metaclass.WithFormMethod withFormMethod
           
 
Fields inherited from class org.codehaus.groovy.grails.plugins.web.api.CommonWebApi
RAW_CODEC_NAME
 
Constructor Summary
ControllersApi()
           
ControllersApi(org.codehaus.groovy.grails.plugins.GrailsPluginManager pluginManager)
           
 
Method Summary
<T> void
bindData(java.lang.Object instance, java.lang.Class<T> targetType, java.util.Collection<T> collectionToPopulate, org.grails.databinding.CollectionDataBindingSource collectionBindingSource)
           
<T> void
bindData(java.lang.Object instance, java.lang.Class<T> targetType, java.util.Collection<T> collectionToPopulate, javax.servlet.ServletRequest request)
           
 java.lang.Object bindData(java.lang.Object instance, java.lang.Object target, java.lang.Object bindingSource)
           
 java.lang.Object bindData(java.lang.Object instance, java.lang.Object target, java.lang.Object bindingSource, java.util.List excludes)
           
 java.lang.Object bindData(java.lang.Object instance, java.lang.Object target, java.lang.Object bindingSource, java.util.List excludes, java.lang.String filter)
           
 java.lang.Object bindData(java.lang.Object instance, java.lang.Object target, java.lang.Object bindingSource, java.util.Map includeExclude)
           
 java.lang.Object bindData(java.lang.Object instance, java.lang.Object target, java.lang.Object bindingSource, java.util.Map includeExclude, java.lang.String filter)
           
 java.lang.Object bindData(java.lang.Object instance, java.lang.Object target, java.lang.Object bindingSource, java.lang.String filter)
           
 java.lang.Object chain(java.lang.Object instance, java.util.Map args)
          Invokes the chain method for the given arguments
 java.lang.String forward(java.lang.Object instance, java.util.Map params)
          Forwards a request for the given parameters using the RequestDispatchers forward method
 java.lang.String getActionUri(java.lang.Object instance)
          Returns the URI of the currently executing action
 java.util.Map getChainModel(java.lang.Object instance)
          Obtains the chain model which is used to chain request attributes from one request to the next via flash scope
 java.lang.String getControllerUri(java.lang.Object instance)
          Returns the URI of the currently executing controller
 org.springframework.validation.Errors getErrors(java.lang.Object instance)
          Obtains the errors instance for the current controller
 java.lang.reflect.Method getExceptionHandlerMethodFor(java.lang.Object controllerInstance, java.lang.Class<? extends java.lang.Exception> exceptionType)
           
 org.springframework.web.servlet.ModelAndView getModelAndView(java.lang.Object instance)
          Obtains the ModelAndView for the currently executing controller
static org.springframework.context.ApplicationContext getStaticApplicationContext()
           
 java.lang.String getTemplateUri(java.lang.Object instance, java.lang.String name)
          Obtains a URI of a template by name
 java.lang.String getViewUri(java.lang.Object instance, java.lang.String name)
          Obtains a URI of a view by name
 boolean hasErrors(java.lang.Object instance)
          Return true if there are an errors
 void header(java.lang.Object instance, java.lang.String headerName, java.lang.Object headerValue)
          Sets a response header for the given name and value
static void initialize(java.lang.Object instance)
          Constructor used by controllers
 java.lang.Object initializeCommandObject(java.lang.Object controllerInstance, java.lang.Class type)
          Initializes a command object.
protected  java.lang.Object invokeRender(java.lang.Object instance, java.lang.Object... args)
           
 java.lang.Object redirect(java.lang.Object instance, java.util.Map args)
          Redirects for the given arguments.
 java.lang.Object redirect(java.lang.Object instance, java.lang.Object object)
          Redirects for the given arguments.
 java.lang.Object render(java.lang.Object instance, groovy.lang.Closure c)
           
 java.lang.Object render(java.lang.Object instance, java.util.Map args)
           
 java.lang.Object render(java.lang.Object instance, java.util.Map args, groovy.lang.Closure c)
           
 java.lang.Object render(java.lang.Object instance, java.lang.Object o)
           
 java.lang.Object render(java.lang.Object instance, java.lang.String txt)
           
 void setErrors(java.lang.Object instance, org.springframework.validation.Errors errors)
          Sets the errors instance of the current controller
 void setGspEncoding(java.lang.String gspEncoding)
           
 void setLinkGenerator(org.codehaus.groovy.grails.web.mapping.LinkGenerator linkGenerator)
           
 void setModelAndView(java.lang.Object instance, org.springframework.web.servlet.ModelAndView mav)
          Sets the ModelAndView of the current controller
 void setRedirectListeners(java.util.Collection<org.codehaus.groovy.grails.web.servlet.mvc.RedirectEventListener> redirectListeners)
           
 void setUseJessionId(boolean useJessionId)
           
 java.lang.Object withForm(java.lang.Object instance, groovy.lang.Closure callable)
          Used the synchronizer token pattern to avoid duplicate form submissions
 
Methods inherited from class org.codehaus.groovy.grails.plugins.web.api.CommonWebApi
currentRequestAttributes, getActionName, getApplicationContext, getControllerName, getFlash, getGrailsApplication, getGrailsAttributes, getParams, getPluginContextPath, getRequest, getResponse, getServletContext, getSession, getWebRequest, raw, setApplicationContext, setGrailsApplication, setServletContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RENDER_METHOD_NAME

protected static final java.lang.String RENDER_METHOD_NAME
See Also:
Constant Field Values

BIND_DATA_METHOD

protected static final java.lang.String BIND_DATA_METHOD
See Also:
Constant Field Values

SLASH

protected static final java.lang.String SLASH
See Also:
Constant Field Values

redirect

protected transient RedirectDynamicMethod redirect

render

protected transient RenderDynamicMethod render

withFormMethod

protected transient org.codehaus.groovy.grails.web.metaclass.WithFormMethod withFormMethod

forwardMethod

protected transient org.codehaus.groovy.grails.web.metaclass.ForwardMethod forwardMethod
Constructor Detail

ControllersApi

public ControllersApi()

ControllersApi

public ControllersApi(org.codehaus.groovy.grails.plugins.GrailsPluginManager pluginManager)
Method Detail

getStaticApplicationContext

public static org.springframework.context.ApplicationContext getStaticApplicationContext()

setGspEncoding

public void setGspEncoding(java.lang.String gspEncoding)

setRedirectListeners

public void setRedirectListeners(java.util.Collection<org.codehaus.groovy.grails.web.servlet.mvc.RedirectEventListener> redirectListeners)

setUseJessionId

public void setUseJessionId(boolean useJessionId)

setLinkGenerator

public void setLinkGenerator(org.codehaus.groovy.grails.web.mapping.LinkGenerator linkGenerator)

initialize

public static void initialize(java.lang.Object instance)
Constructor used by controllers

Parameters:
instance - The instance

getActionUri

public java.lang.String getActionUri(java.lang.Object instance)
Returns the URI of the currently executing action

Returns:
The action URI

getControllerUri

public java.lang.String getControllerUri(java.lang.Object instance)
Returns the URI of the currently executing controller

Returns:
The controller URI

getTemplateUri

public java.lang.String getTemplateUri(java.lang.Object instance,
                                       java.lang.String name)
Obtains a URI of a template by name

Parameters:
name - The name of the template
Returns:
The template URI

getViewUri

public java.lang.String getViewUri(java.lang.Object instance,
                                   java.lang.String name)
Obtains a URI of a view by name

Parameters:
name - The name of the view
Returns:
The template URI

setErrors

public void setErrors(java.lang.Object instance,
                      org.springframework.validation.Errors errors)
Sets the errors instance of the current controller

Parameters:
errors - The error instance

getErrors

public org.springframework.validation.Errors getErrors(java.lang.Object instance)
Obtains the errors instance for the current controller

Returns:
The Errors instance

setModelAndView

public void setModelAndView(java.lang.Object instance,
                            org.springframework.web.servlet.ModelAndView mav)
Sets the ModelAndView of the current controller

Parameters:
mav - The ModelAndView

getModelAndView

public org.springframework.web.servlet.ModelAndView getModelAndView(java.lang.Object instance)
Obtains the ModelAndView for the currently executing controller

Returns:
The ModelAndView

getChainModel

public java.util.Map getChainModel(java.lang.Object instance)
Obtains the chain model which is used to chain request attributes from one request to the next via flash scope

Returns:
The chainModel

hasErrors

public boolean hasErrors(java.lang.Object instance)
Return true if there are an errors

Returns:
true if there are errors

redirect

public java.lang.Object redirect(java.lang.Object instance,
                                 java.util.Map args)
Redirects for the given arguments.

Parameters:
args - The arguments
Returns:
null

redirect

public java.lang.Object redirect(java.lang.Object instance,
                                 java.lang.Object object)
Redirects for the given arguments.

Parameters:
object - A domain class
Returns:
null

chain

public java.lang.Object chain(java.lang.Object instance,
                              java.util.Map args)
Invokes the chain method for the given arguments

Parameters:
instance - The instance
args - The arguments
Returns:
Result of the redirect call

render

public java.lang.Object render(java.lang.Object instance,
                               java.lang.Object o)

render

public java.lang.Object render(java.lang.Object instance,
                               java.lang.String txt)

render

public java.lang.Object render(java.lang.Object instance,
                               java.util.Map args)

render

public java.lang.Object render(java.lang.Object instance,
                               groovy.lang.Closure c)

render

public java.lang.Object render(java.lang.Object instance,
                               java.util.Map args,
                               groovy.lang.Closure c)

invokeRender

protected java.lang.Object invokeRender(java.lang.Object instance,
                                        java.lang.Object... args)

bindData

public java.lang.Object bindData(java.lang.Object instance,
                                 java.lang.Object target,
                                 java.lang.Object bindingSource,
                                 java.util.List excludes)

bindData

public java.lang.Object bindData(java.lang.Object instance,
                                 java.lang.Object target,
                                 java.lang.Object bindingSource,
                                 java.util.List excludes,
                                 java.lang.String filter)

bindData

public java.lang.Object bindData(java.lang.Object instance,
                                 java.lang.Object target,
                                 java.lang.Object bindingSource,
                                 java.util.Map includeExclude)

bindData

public java.lang.Object bindData(java.lang.Object instance,
                                 java.lang.Object target,
                                 java.lang.Object bindingSource,
                                 java.lang.String filter)

bindData

public java.lang.Object bindData(java.lang.Object instance,
                                 java.lang.Object target,
                                 java.lang.Object bindingSource)

bindData

public java.lang.Object bindData(java.lang.Object instance,
                                 java.lang.Object target,
                                 java.lang.Object bindingSource,
                                 java.util.Map includeExclude,
                                 java.lang.String filter)

bindData

public <T> void bindData(java.lang.Object instance,
                         java.lang.Class<T> targetType,
                         java.util.Collection<T> collectionToPopulate,
                         javax.servlet.ServletRequest request)
              throws java.lang.Exception
Throws:
java.lang.Exception

bindData

public <T> void bindData(java.lang.Object instance,
                         java.lang.Class<T> targetType,
                         java.util.Collection<T> collectionToPopulate,
                         org.grails.databinding.CollectionDataBindingSource collectionBindingSource)
              throws java.lang.Exception
Throws:
java.lang.Exception

header

public void header(java.lang.Object instance,
                   java.lang.String headerName,
                   java.lang.Object headerValue)
Sets a response header for the given name and value

Parameters:
instance - The instance
headerName - The header name
headerValue - The header value

withForm

public java.lang.Object withForm(java.lang.Object instance,
                                 groovy.lang.Closure callable)
Used the synchronizer token pattern to avoid duplicate form submissions

Parameters:
instance - The instance
callable - The closure to execute
Returns:
The result of the closure execution

forward

public java.lang.String forward(java.lang.Object instance,
                                java.util.Map params)
Forwards a request for the given parameters using the RequestDispatchers forward method

Parameters:
instance - The instance
params - The parameters
Returns:
The forwarded URL

initializeCommandObject

public java.lang.Object initializeCommandObject(java.lang.Object controllerInstance,
                                                java.lang.Class type)
                                         throws java.lang.Exception
Initializes a command object. If type is a domain class and the request body or parameters include an id, the id is used to retrieve the command object instance from the database, otherwise the no-arg constructor on type is invoke. If an attempt is made to retrieve the command object instance from the database and no corresponding record is found, null is returned. The command object is then subjected to data binding and dependency injection before being returned.

Parameters:
controllerInstance - The controller instance
type - The type of the command object
Returns:
the initialized command object or null if the command object is a domain class, the body or parameters included an id and no corresponding record was found in the database.
Throws:
java.lang.Exception

getExceptionHandlerMethodFor

public java.lang.reflect.Method getExceptionHandlerMethodFor(java.lang.Object controllerInstance,
                                                             java.lang.Class<? extends java.lang.Exception> exceptionType)
                                                      throws java.lang.Exception
Throws:
java.lang.Exception