# controllers

## Purpose

A plug-in that sets up core Grails MVC architecture using the underlying Spring MVC component model

## Examples

A controller:

    class BookController {
    	def list = {
    		books:Book.list()
    	}
    }

A tag library:

    import java.text.*
    class FormatTagLib {
    	def dateFormat = { attrs ->
    		out << new SimpleDateFormat(attrs.format).format(attrs.value)
    	}
    }

## Description

This plug-in deals with setting up Grails to use Spring MVC at its core to deal with web requests. The plug-in sets up the `GrailsDispatcherServlet` and necessary Spring beans (see below) for controllers, tag libraries and Groovy Server Pages (GSP)

Configured Spring Beans:

- `exceptionHandler` - An instance of org.codehaus.groovy.grails.web.errors.GrailsExceptionResolver for dealing with exceptions
- `multipartResolver` - An instance of org.springframework.web.multipart.commons.CommonsMultipartResolver used for dealing with file uploads using Apache Commons File Upload. If you do not wish to use this, set grails.disableCommonsMultipart to true in Config.groovy. Be aware that disabling multipart handling will effect the behaviour of g:actionSubmit which needs to inspect the parameters (requiring the multipart request to be parsed) during the URL mapping phase.
- `simpleGrailsController` - An instance of org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController, which is an instance of the Spring MVC Controller interface and deals with delegating onto actual Grails controller classes
- `groovyPageResourceLoader` - Configured in `development` mode only or when the `grails.gsp.view.dir` is set. This is a Spring ResourceLoader that knows how to load GSP views from the an arbitrary location
- `groovyPagesTemplateEngine` - An instance of org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateEngine, this class deals with rendering of GSP views
- `jspViewResolver` - An instance of org.codehaus.groovy.grails.web.servlet.view.GrailsViewResolver that knows how to resolve GSP views and is environment aware

The plug-in will also configure each Grails controller class as a prototyped Spring bean and each Grails tag library as a singleton Spring bean