Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Panel
bgColor#FFFFCE
titleWhere is the object coming from?
borderStylesolid
Wiki Markup

We need to look carefully at the "object" argument.  The object here is a Command.  LoginController extends SimpleFormController which extends AbstractFormController which extends BaseCommandController which extends AbstractController which extends WebContentGenerator which extends WebApplicationObjectSupport which extends ApplicationObjectSupport.   In Spring Web MVC FormControllers, the forms play the role of "commands" in the more general CommandController model
.

LoginController defaults this Command class:

Code Block
titleLoginController afterPropertiesSet() excerpt
.


So, in AbstractController there is a final method handleRequest():

{code:title=AbstractController handleRequest()}
public final ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		// delegate to WebContentGenerator for checking and preparing
		checkAndPrepare(request, response, this instanceof LastModified);

		// execute in synchronized block if required
		if (this.synchronizeOnSession) {
			HttpSession session = request.getSession(false);
			if (session != null) {
				synchronized (session) {
					return handleRequestInternal(request, response);
				}
			}
		}
		
		return handleRequestInternal(request, response);
	}
{code}

As we can see here, it delegates to the method handleRequestInternal(), which is declared to be abstract:

{code|title=AbstractController handleRequestInternal()}
/**
	 * Template method. Subclasses must implement this.
	 * The contract is the same as for handleRequest.
	 * @see #handleRequest
	 */
	protected abstract ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
	    throws Exception;

{code}

LoginController defaults this Command class:

{code:title=LoginController afterPropertiesSet() excerpt}
  public void afterPropertiesSet() throws Exception {

        if (this.getCommandClass() == null) {
            this.setCommandName("credentials");
            this.setCommandClass(UsernamePasswordCredentials.class);
{code}


In BaseCommandController, we have:


{code
:title
=BaseCommandController getCommand()
}
/**
 * Retrieve a command object for the given request.
 * <p>Default implementation calls createCommand. Subclasses can override this.
 * @param request current HTTP request
 * @return object command to bind onto
 * @see #createCommand
 */
 protected Object getCommand(HttpServletRequest request) throws Exception {
    return createCommand();
 }
{code}

And the createCommand() method to which it delegates:


{code
:title
=BaseCommandController createCommand()
}
/**
 * Create a new command instance for the command class of this controller.
 * @return the new command instance
 * @throws InstantiationException if the command class could not be instantiated
 * @throws IllegalAccessException if the class or its constructor is not accessible
 */
 protected final Object createCommand() throws InstantiationException, IllegalAccessException {
    if (this.commandClass == null) {
         throw new IllegalStateException("Cannot create command without commandClass being set - " +
            "either set commandClass or override formBackingObject");
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Creating new command of class [" + this.commandClass.getName() + "]");
    }
    return this.commandClass.newInstance();
 }
{code}

Code Block
titleCurrent CredentialsBinder interface
/**
 * Interface for a class that can bind items stored in the request to a particular
 * credentials implementation.  This allows for binding beyond the basic
 * JavaBean/Request parameter binding that is handled by Spring automatically.
 */
public interface CredentialsBinder {
    /**
    * Method to allow manually binding attributes from the request object to properties of
    * the credentials.  Useful when there is no mapping of attribute to property for the 
    * usual Spring binding to handle.
    * 
    * @param request The HttpServletRequest from which we wish to bind credentials to
    * @param credentials The credentials we will be doing custom binding to.
    */
    void bind(HttpServletRequest request, Credentials credentials);
	
    /**
    * 
    * Method to determine if a CredentialsBinder supports a specific class or not.
    * 
    * @param clazz The class to determine is supported or not
    * @return true if this class is supported by the CredentialsBinder, false otherwise.
    */
    boolean supports(Class clazz);
}