Anyframe Web

anyframe.web.springmvc.controller
Class AnyframeFormController

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.springframework.web.servlet.mvc.BaseCommandController
                      extended by org.springframework.web.servlet.mvc.AbstractFormController
                          extended by org.springframework.web.servlet.mvc.SimpleFormController
                              extended by anyframe.web.springmvc.controller.AnyframeFormController
All Implemented Interfaces:
org.springframework.context.ApplicationContextAware, org.springframework.context.MessageSourceAware, org.springframework.web.context.ServletContextAware, org.springframework.web.servlet.mvc.Controller
Direct Known Subclasses:
AnyframeMiPController

public class AnyframeFormController
extends org.springframework.web.servlet.mvc.SimpleFormController
implements org.springframework.context.MessageSourceAware

AnyframeFormController Class which provide exception, pre/post execution features.

We changed org.springframework.web.servlet.mvc.SimpleFormController,org.springframework.web.servlet.mvc.multiaction.MultiActionController Class into anyframe.web.springmvc.common.controller.AnyframeFormController

Author:
Juergen Hoeller, Rod Johnson, modified by Sooyeon Park

Field Summary
static java.lang.String LAST_MODIFIED_METHOD_SUFFIX
          Suffix for last-modified methods
static java.lang.String PAGE_NOT_FOUND_LOG_CATEGORY
          Log category to use when no mapped handler is found for a request.
protected static org.apache.commons.logging.Log pageNotFoundLogger
          Additional logger to use when no mapped handler is found for a request.
 
Fields inherited from class org.springframework.web.servlet.mvc.BaseCommandController
DEFAULT_COMMAND_NAME
 
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
AnyframeFormController()
           
 
Method Summary
protected  void bind(javax.servlet.http.HttpServletRequest request, java.lang.Object command)
          Bind request parameters onto the given command bean
protected  java.lang.reflect.Method getExceptionHandler(java.lang.Throwable exception)
          Determine the exception handler method for the given exception.
 long getLastModified(javax.servlet.http.HttpServletRequest request)
          Try to find an XXXXLastModified method, where XXXX is the name of a handler.
 org.apache.commons.logging.Log getLogger()
           
 org.springframework.web.servlet.mvc.multiaction.MethodNameResolver getMethodNameResolver()
          Return the MethodNameResolver used by this class.
 java.lang.String getSuccess_add()
           
 java.lang.String getSuccess_addView()
           
 java.lang.String getSuccess_delete()
           
 java.lang.String getSuccess_get()
           
 java.lang.String getSuccess_list()
           
 java.lang.String getSuccess_update()
           
protected  org.springframework.web.servlet.ModelAndView handleInvalidSubmit(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          preventing duplicate form submission and then show the message that key is "common.msg.invalidtoken.error"
protected  org.springframework.web.servlet.ModelAndView handleNoSuchRequestHandlingMethod(org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException ex, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Handle the case where no request handler method was found.
protected  org.springframework.web.servlet.ModelAndView handleRequestInternal(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Determine a handler method and invoke it.
protected  void initBinder(javax.servlet.http.HttpServletRequest request, org.springframework.web.bind.ServletRequestDataBinder binder)
          Support binding of Date type.
protected  org.springframework.web.servlet.ModelAndView invokeNamedMethod(java.lang.String methodName, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Invokes the named method.
 boolean isShowNewForm()
           
protected  java.lang.Object newCommandObject(java.lang.Class clazz)
          Create a new command object of the given class.
 org.springframework.web.servlet.ModelAndView onSubmit(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object command, org.springframework.validation.BindException errors)
          Submit callback with all parameters.
protected  void postProcess(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected  void preProcess(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected  org.springframework.web.servlet.ModelAndView process(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Determine a handler method and invoke it.
protected  org.springframework.web.servlet.ModelAndView processCheckedException(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Exception checkedException)
           
protected  org.springframework.web.servlet.ModelAndView processFinally(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.web.servlet.ModelAndView result)
           
protected  org.springframework.web.servlet.ModelAndView processUnCheckedException(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.RuntimeException uncheckedException)
           
 void setDelegate(java.lang.Object delegate)
          Set the delegate used by this class; the default is this, assuming that handler methods have been added by a subclass.
 void setMessageSource(org.springframework.context.MessageSource messageSource)
           
 void setMethodNameResolver(org.springframework.web.servlet.mvc.multiaction.MethodNameResolver methodNameResolver)
          Set the method name resolver that this class should use.
 void setShowNewForm(boolean showNewForm)
           
 void setSuccess_add(java.lang.String success_add)
           
 void setSuccess_addView(java.lang.String success_addView)
           
 void setSuccess_delete(java.lang.String success_delete)
           
 void setSuccess_get(java.lang.String success_get)
           
 void setSuccess_list(java.lang.String success_list)
           
 void setSuccess_update(java.lang.String success_update)
           
 
Methods inherited from class org.springframework.web.servlet.mvc.SimpleFormController
doSubmitAction, getFormView, getSuccessView, isFormChangeRequest, isFormChangeRequest, onFormChange, onFormChange, onSubmit, onSubmit, processFormSubmission, referenceData, referenceData, setFormView, setSuccessView, showForm, showForm, suppressValidation
 
Methods inherited from class org.springframework.web.servlet.mvc.AbstractFormController
currentFormObject, formBackingObject, getCommand, getErrorsForNewForm, getFormSessionAttributeName, getFormSessionAttributeName, isBindOnNewForm, isFormSubmission, isSessionForm, onBindOnNewForm, onBindOnNewForm, setBindOnNewForm, setSessionForm, showForm, showForm, showNewForm
 
Methods inherited from class org.springframework.web.servlet.mvc.BaseCommandController
bindAndValidate, checkCommand, createBinder, createCommand, getBindingErrorProcessor, getCommandClass, getCommandName, getMessageCodesResolver, getPropertyEditorRegistrars, getValidator, getValidators, getWebBindingInitializer, initApplicationContext, isValidateOnBinding, onBind, onBind, onBindAndValidate, prepareBinder, setBindingErrorProcessor, setCommandClass, setCommandName, setMessageCodesResolver, setPropertyEditorRegistrar, setPropertyEditorRegistrars, setValidateOnBinding, setValidator, setValidators, setWebBindingInitializer, suppressBinding, suppressValidation, suppressValidation, useDirectFieldAccess
 
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, isUseCacheControlNoStore, isUseExpiresHeader, preventCaching, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseCacheControlNoStore, setUseExpiresHeader
 
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
 
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LAST_MODIFIED_METHOD_SUFFIX

public static final java.lang.String LAST_MODIFIED_METHOD_SUFFIX
Suffix for last-modified methods

See Also:
Constant Field Values

PAGE_NOT_FOUND_LOG_CATEGORY

public static final java.lang.String PAGE_NOT_FOUND_LOG_CATEGORY
Log category to use when no mapped handler is found for a request.

See Also:
pageNotFoundLogger, Constant Field Values

pageNotFoundLogger

protected static final org.apache.commons.logging.Log pageNotFoundLogger
Additional logger to use when no mapped handler is found for a request.

See Also:
PAGE_NOT_FOUND_LOG_CATEGORY
Constructor Detail

AnyframeFormController

public AnyframeFormController()
Method Detail

setMessageSource

public void setMessageSource(org.springframework.context.MessageSource messageSource)
Specified by:
setMessageSource in interface org.springframework.context.MessageSourceAware

getLogger

public org.apache.commons.logging.Log getLogger()
                                         throws java.lang.Exception
Throws:
java.lang.Exception

getSuccess_list

public java.lang.String getSuccess_list()

setSuccess_list

public void setSuccess_list(java.lang.String success_list)

getSuccess_get

public java.lang.String getSuccess_get()

setSuccess_get

public void setSuccess_get(java.lang.String success_get)

getSuccess_update

public java.lang.String getSuccess_update()

setSuccess_update

public void setSuccess_update(java.lang.String success_update)

getSuccess_add

public java.lang.String getSuccess_add()

setSuccess_add

public void setSuccess_add(java.lang.String success_add)

getSuccess_delete

public java.lang.String getSuccess_delete()

setSuccess_delete

public void setSuccess_delete(java.lang.String success_delete)

getSuccess_addView

public java.lang.String getSuccess_addView()

setSuccess_addView

public void setSuccess_addView(java.lang.String success_addView)

isShowNewForm

public boolean isShowNewForm()

setShowNewForm

public void setShowNewForm(boolean showNewForm)

onSubmit

public org.springframework.web.servlet.ModelAndView onSubmit(javax.servlet.http.HttpServletRequest request,
                                                             javax.servlet.http.HttpServletResponse response,
                                                             java.lang.Object command,
                                                             org.springframework.validation.BindException errors)
                                                      throws java.lang.Exception
Submit callback with all parameters. Called in case of submit without errors reported by the registered validator, or on every submit if no validator.

The default implementation delegates to SimpleFormController.onSubmit(Object, BindException). For simply performing a submit action and rendering the specified success view, consider implementing SimpleFormController.doSubmitAction(java.lang.Object) rather than an onSubmit variant.

Subclasses can override this to provide custom submission handling like storing the object to the database. Implementations can also perform custom validation and call showForm to return to the form. Do not implement multiple onSubmit methods: In that case, just this method will be called by the controller.

Call errors.getModel() to populate the ModelAndView model with the command and the Errors instance, under the specified command name, as expected by the "spring:bind" tag.

Overrides:
onSubmit in class org.springframework.web.servlet.mvc.SimpleFormController
Parameters:
request - current servlet request
response - current servlet response
command - form object with request parameters bound onto it
errors - Errors instance without errors (subclass can add errors if it wants to)
Returns:
the prepared model and view, or null
Throws:
java.lang.Exception - in case of errors
See Also:
SimpleFormController.onSubmit(Object, BindException), SimpleFormController.doSubmitAction(java.lang.Object), SimpleFormController.showForm(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.springframework.validation.BindException), Errors, BindException.getModel()

preProcess

protected void preProcess(javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response)
                   throws java.lang.Exception
Throws:
java.lang.Exception

postProcess

protected void postProcess(javax.servlet.http.HttpServletRequest request,
                           javax.servlet.http.HttpServletResponse response)
                    throws java.lang.Exception
Throws:
java.lang.Exception

processCheckedException

protected org.springframework.web.servlet.ModelAndView processCheckedException(javax.servlet.http.HttpServletRequest request,
                                                                               javax.servlet.http.HttpServletResponse response,
                                                                               java.lang.Exception checkedException)
                                                                        throws java.lang.Exception
Throws:
java.lang.Exception

processUnCheckedException

protected org.springframework.web.servlet.ModelAndView processUnCheckedException(javax.servlet.http.HttpServletRequest request,
                                                                                 javax.servlet.http.HttpServletResponse response,
                                                                                 java.lang.RuntimeException uncheckedException)
                                                                          throws java.lang.Exception
Throws:
java.lang.Exception

processFinally

protected org.springframework.web.servlet.ModelAndView processFinally(javax.servlet.http.HttpServletRequest request,
                                                                      javax.servlet.http.HttpServletResponse response,
                                                                      org.springframework.web.servlet.ModelAndView result)
                                                               throws java.lang.Exception
Throws:
java.lang.Exception

handleRequestInternal

protected org.springframework.web.servlet.ModelAndView handleRequestInternal(javax.servlet.http.HttpServletRequest request,
                                                                             javax.servlet.http.HttpServletResponse response)
                                                                      throws java.lang.Exception
Determine a handler method and invoke it.

Overrides:
handleRequestInternal in class org.springframework.web.servlet.mvc.AbstractFormController
Throws:
java.lang.Exception
See Also:
MethodNameResolver.getHandlerMethodName(javax.servlet.http.HttpServletRequest), invokeNamedMethod(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse), handleNoSuchRequestHandlingMethod(org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

process

protected org.springframework.web.servlet.ModelAndView process(javax.servlet.http.HttpServletRequest request,
                                                               javax.servlet.http.HttpServletResponse response)
                                                        throws java.lang.Exception
Determine a handler method and invoke it.

Throws:
java.lang.Exception
See Also:
MethodNameResolver.getHandlerMethodName(javax.servlet.http.HttpServletRequest), invokeNamedMethod(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse), handleNoSuchRequestHandlingMethod(org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

setDelegate

public final void setDelegate(java.lang.Object delegate)
Set the delegate used by this class; the default is this, assuming that handler methods have been added by a subclass.

This method does not get invoked once the class is configured.

Parameters:
delegate - an object containing handler methods
Throws:
java.lang.IllegalStateException - if no handler methods are found

setMethodNameResolver

public final void setMethodNameResolver(org.springframework.web.servlet.mvc.multiaction.MethodNameResolver methodNameResolver)
Set the method name resolver that this class should use.

Allows parameterization of handler method mappings.


getMethodNameResolver

public final org.springframework.web.servlet.mvc.multiaction.MethodNameResolver getMethodNameResolver()
Return the MethodNameResolver used by this class.


getLastModified

public long getLastModified(javax.servlet.http.HttpServletRequest request)
Try to find an XXXXLastModified method, where XXXX is the name of a handler. Return -1 if there's no such handler, indicating that content must be updated.

See Also:
LastModified.getLastModified(HttpServletRequest)

handleNoSuchRequestHandlingMethod

protected org.springframework.web.servlet.ModelAndView handleNoSuchRequestHandlingMethod(org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException ex,
                                                                                         javax.servlet.http.HttpServletRequest request,
                                                                                         javax.servlet.http.HttpServletResponse response)
                                                                                  throws java.lang.Exception
Handle the case where no request handler method was found.

The default implementation logs a warning and sends an HTTP 404 error. Alternatively, a fallback view could be chosen, or the NoSuchRequestHandlingMethodException could be rethrown as-is.

Parameters:
ex - the NoSuchRequestHandlingMethodException to be handled
request - current HTTP request
response - current HTTP response
Returns:
a ModelAndView to render, or null if handled directly
Throws:
java.lang.Exception - an Exception that should be thrown as result of the servlet request

invokeNamedMethod

protected final org.springframework.web.servlet.ModelAndView invokeNamedMethod(java.lang.String methodName,
                                                                               javax.servlet.http.HttpServletRequest request,
                                                                               javax.servlet.http.HttpServletResponse response)
                                                                        throws java.lang.Exception
Invokes the named method.

Uses a custom exception handler if possible; otherwise, throw an unchecked exception; wrap a checked exception or Throwable.

Throws:
java.lang.Exception

newCommandObject

protected java.lang.Object newCommandObject(java.lang.Class clazz)
                                     throws java.lang.Exception
Create a new command object of the given class.

This implementation uses BeanUtils.instantiateClass, so commands need to have public no-arg constructors. Subclasses can override this implementation if desired.

Throws:
java.lang.Exception - if the command object could not be instantiated
See Also:
BeanUtils.instantiateClass(Class)

bind

protected void bind(javax.servlet.http.HttpServletRequest request,
                    java.lang.Object command)
             throws java.lang.Exception
Bind request parameters onto the given command bean

Parameters:
request - request from which parameters will be bound
command - command object, that must be a JavaBean
Throws:
java.lang.Exception - in case of invalid state or arguments

getExceptionHandler

protected java.lang.reflect.Method getExceptionHandler(java.lang.Throwable exception)
Determine the exception handler method for the given exception.

Can return null if not found.

Parameters:
exception - the exception to handle
Returns:
a handler for the given exception type, or null

handleInvalidSubmit

protected org.springframework.web.servlet.ModelAndView handleInvalidSubmit(javax.servlet.http.HttpServletRequest request,
                                                                           javax.servlet.http.HttpServletResponse response)
                                                                    throws java.lang.Exception
preventing duplicate form submission and then show the message that key is "common.msg.invalidtoken.error"

Overrides:
handleInvalidSubmit in class org.springframework.web.servlet.mvc.AbstractFormController
Throws:
java.lang.Exception

initBinder

protected void initBinder(javax.servlet.http.HttpServletRequest request,
                          org.springframework.web.bind.ServletRequestDataBinder binder)
                   throws java.lang.Exception
Support binding of Date type.

Overrides:
initBinder in class org.springframework.web.servlet.mvc.BaseCommandController
Throws:
java.lang.Exception

Anyframe Web

Copyright © 2008-2009 Samsung SDS. All Rights Reserved.