Grails Controllers
What is a controller?
A controller handles requests and creates or prepares the response. They can generate the response or delegate to a view. To create a controller simply create a class whose name ends with "Controller" and place it within the "grails-app/controllers" directory.
The first part of your controller name is mapped to a URI and each action defined within your controller maps to URI within the controller name URI.
Controllers are request-scoped. A new instance is created for each request.
Comments (4)
Oct 07, 2007
Burkard Endres says:
i tried to write a simple controller to try out grails a little, but i could not...i tried to write a simple controller to try out grails a little, but i could not manage to set an attribute to a session.
i tried
this.session["books",Book.findAll()]
and this.session["books"] = Book.findAll()
what i found similar in some example. Could you please provide a proper example how Attributes should be set to request, session and application scope?
thanks
Feb 06, 2006
Burkard Endres says:
this.session.books = Book.findAll()] this.session["books"] = Book.findAll()] s...this.session.books = Book.findAll()]
this.session["books"] = Book.findAll()]
should work
Feb 06, 2006
Burkard Endres says:
of course this.session.books = Book.findAll() this.session["books"] = Book.fin...of course
this.session.books = Book.findAll()
this.session["books"] = Book.findAll()
should work
Jul 09, 2007
Kristian Mandrup says:
You often need the ability to attach multiple filesto a domain object. One way ...You often need the ability to attach multiple filesto a domain object.
One way to do this would be to create an Attachment domain class with a byte[] file property and some metadata properties such as date, name, description tags etc. Then have your "core" domain object contain a static hasMany = [attachments:Attachment, ...]
Would be nice to have a simple way to bind such Attachments these to a form supporting multiple file uploads.
Fx pseudo-code
$
<input type="file" name="$
$
The following blog http://xytang.blogspot.com/2007/03/web-form-based-pdfs-merger-task-provide.html
contains an example to start from. Would be nice to generalize this for easier reuse! Any ideas? Maybe already supported using some Ajax magic/widgets?
Cheers!