Grails : Controller Dynamic Methods
This page last changed on Mar 15, 2006 by [email protected].
Controller Dynamic Methods & PropertiesPropertiesactionUriDescriptionThe relative Uri of the action controllerUriDescriptionThe relative Uri of the controller flashDescriptionA map that allows temporary storage of objects for the next request and the next request only. The subequent request will clear the storage of any variables stored in the first Exampleflash['message'] = 'hello world!' grailsAttributesDescriptionAn instance of org.codehaus.groovy.grails.web.servlet.GrailsApplicationAttributes that provides convenience methods for the current grails request Exampledef templateUri = grailsAttributes.getTemplateUri("myTemplate",request)
paramsDescriptionA map of the available request parameters and/or controller parameters Exampledef a = Account.get( params["id"] )
requestDescriptionThe HttpServletRequest instance for the request. Request attributes can be accessed with the Map syntax provided by groovy Examplerequest['anAttribute']
request.getHeader("user-agent")
responseDescriptionThe HttpServletResponse instance Exampleresponse.setHeader("myheader", "myvalue") servletContextDescriptionThe ServletContext instance as per the servlet API Exampledef myUrl = servletContext.getResource("/path/to/url")
sessionDescriptionProvides access to a map of the HttpSession instance Exampledef loggedUser = session["loggedUser"]
MethodsbindDataDescriptionBinds data to a target instance performing type conversion if necessary. Useful for binding request parameters to properties of objects Parameters
ExamplesbindData(target, this.params) // binds request parameters to a target object chainDescriptionChains the model (The model is retained from one action to the next) from one action to the next allowing you to build up the model from an action chain. Parameters
Exampleschain(action:"details",model:[book:new Book(title:'The Shawshank Redemption')]) redirectDescriptionRedirects the current action to another action, optionally passing parameters and/or errors Parameters
Examplesredirect(uri:"book/list") redirect(action:"show") redirect(controller:"book",action:"list") redirect(action:"show",id:4, params:[author:"Stephen King"]) renderDescriptionA multi-purpose method for rendering responses to the client which is best illustrated with a few examples! Parameters
Examples// renders text to response render "some text" // renders text for a specified content-type/encoding render(text:"<xml>some xml</xml>",contentType:"text/xml",encoding:"UTF-8") // render a template to the response for the specified model render(template:"book",model:[book:new Book(title:'The Shining',author:'Stephen King')]) // render each item in the collection using the specified template render(template:"book",collection:[b1, b2, b3]) // render a template to the response for the specified bean render(template:"book",bean:new Book(title:'The Shining',author:'Stephen King')) // render the view with the specified model render(view:"viewName",model:[book:new Book(author:'Stephen King')]) // render the view with the controller as the model render(view:"viewName" ) // render some markup to the response render { div(id:"myDiv") { "some body text" } } // render some XML markup to the response render(contentType:"text/xml") { books { for(b in books) { book(title:b.title,author:b.author) } } } // render an OpenRico (http://www.openrico.org) response with the builder attribute: def b = new Book(title:"Kiss the Girls", author:"James Patterson") render(builder:"rico") { object(id:"bookUpdater") { book(author:b.title,author:b.author) } } |
![]() |
Document generated by Confluence on Mar 29, 2006 08:46 |