SlideShare a Scribd company logo
Grails Controller...
Controllers
A controller handles requests and creates or prepares the
response.
A controller can generate the response directly or delegate to a
view.
Destination folder: grails-app/controllers directory
Create a controller
Command : grails create-controller book
package myapp
class BookController {
def index() { }
}
Structure of controller
class BookController {
def list() {
// do controller logic
// create model
return model
}
}
Closure vs controller
Earlier versions of Grails actions were implemented with Closures. This is still
supported, but the preferred approach is to use methods.
Leveraging methods instead of Closure properties has some advantages:
1. Memory efficient
2. Allow use of stateless controllers (singleton scope)
3. You can override actions from subclasses and call the overridden superclass
method with super.actionName()
Default action rules
If there is only one action, it's the default
If you have an action named index, it's the default
Alternatively you can set it explicitly with the defaultAction property:
static defaultAction = "list"
Scopes available in controllers
servletContext - Also known as application scope, this scope lets you share state
across the entire web application. The servletContext is an instance of
ServletContext
session - The session allows associating state with a given user and typically uses
cookies to associate a session with a client. The session object is an instance of
HttpSession
request - The request object allows the storage of objects for the current request
only. The request object is an instance of HttpServletRequest
params - Mutable map of incoming request query string or POST parameters
flash - the concept of flash scope as a temporary store to make attributes available
for this request and the next request only. Afterwards the attributes are cleared.
This is useful for setting a message directly before redirecting.
Accessing Scopes
Scoped Controller
prototype (default) - A new controller will be created for each request
(recommended for actions as Closure properties)
session - One controller is created for the scope of a user session
singleton - Only one instance of the controller ever exists (recommended for
actions as methods)
To enable one of the scopes, add a static scope property to your class with one
of the valid scope values listed above, for example
static scope = "singleton"
You can define the default strategy under in Config.groovy with the
grails.controllers.defaultScope key, for example:
grails.controllers.defaultScope = "singleton"
Redirect with controller
// Call the login action within the same class
redirect(action: login)
// Also redirects to the index action in the home controller
redirect(controller: 'home', action: 'index')
// Redirect to an explicit URI
redirect(uri: "/login.html")
// Redirect to a URL
redirect(url: "http://grails.org")
redirect(action: 'myaction', params: [myparam: "myvalue"])
Render with controller
Object for example:
def theShining = new Book(title: 'The Shining', author: 'Stephen King')
render(view: "viewName", model: [book: theShining])
render(template: "book", model: [book: theShining])
@ annotation with controller
package sample
import grails.plugins.springsecurity.Secured
class ScreenController {
def publicPage() {
render "This is a public page"
}
@Secured(['ROLE_COMMON'])
def commonPage() {
render "This is a common role page"
}
}
commonPage - only user with ROLE_COMMON role can access this page.
URLs
The first part of the URL is the application name, or Application Context Root. The next part of the
URL is the controller name.
Notice that the Controller part of UserController gets dropped off, and the first letter is changed to
lowercase.
After the controller name, you’ll see an optional action name. This name corresponds directly to the
action in the Controller.
Controller Interceptors
Before Interception
The beforeInterceptor intercepts processing before the action is executed. If it
returns false then the intercepted action will not be executed.
After Interception
Use the afterInterceptor property to define an interceptor that is executed after an
action
Before Interceptor
After Interceptor
References
http://docs.grails.org/2.1.1/guide/single.html#controllers
http://grails.asia/grails-tutorial-for-beginners-starting-with-controllers/
https://tutorials.techmytalk.com/2014/07/19/grails-scaffolding-controllers-and-views/
Thanks for listening...

More Related Content

What's hot

Designing applications with Redux
Designing applications with ReduxDesigning applications with Redux
Designing applications with Redux
Fernando Daciuk
 
cake phptutorial
cake phptutorialcake phptutorial
cake phptutorial
ice27
 
Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux js
Citrix
 
Using redux
Using reduxUsing redux
Using redux
Jonas Ohlsson Aden
 
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheet
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheetDo something in 5 with gas 4- Get your analytics profiles to a spreadsheet
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheet
Bruce McPherson
 
Do something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing appDo something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing app
Bruce McPherson
 
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Bruce McPherson
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & Tooling
Binary Studio
 
React.js and Redux overview
React.js and Redux overviewReact.js and Redux overview
React.js and Redux overview
Alex Bachuk
 
React 101
React 101React 101
React 101
Casear Chu
 
Redux Universal
Redux UniversalRedux Universal
Redux Universal
Nikolaus Graf
 
React и redux
React и reduxReact и redux
VBA API for scriptDB primer
VBA API for scriptDB primerVBA API for scriptDB primer
VBA API for scriptDB primer
Bruce McPherson
 
Better React state management with Redux
Better React state management with ReduxBetter React state management with Redux
Better React state management with Redux
Maurice De Beijer [MVP]
 
Workshop 22: React-Redux Middleware
Workshop 22: React-Redux MiddlewareWorkshop 22: React-Redux Middleware
Workshop 22: React-Redux Middleware
Visual Engineering
 
Redux js
Redux jsRedux js
Redux js
Nils Petersohn
 
React outbox
React outboxReact outbox
React outbox
Angela Lehru
 
ASP.NET Internals
ASP.NET InternalsASP.NET Internals
ASP.NET Internals
GoSharp
 
React JS and Redux
React JS and ReduxReact JS and Redux
React JS and Redux
Glib Kechyn
 
Dicoding Developer Coaching #32: Android | Reactive Programming dengan RxJava...
Dicoding Developer Coaching #32: Android | Reactive Programming dengan RxJava...Dicoding Developer Coaching #32: Android | Reactive Programming dengan RxJava...
Dicoding Developer Coaching #32: Android | Reactive Programming dengan RxJava...
DicodingEvent
 

What's hot (20)

Designing applications with Redux
Designing applications with ReduxDesigning applications with Redux
Designing applications with Redux
 
cake phptutorial
cake phptutorialcake phptutorial
cake phptutorial
 
Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux js
 
Using redux
Using reduxUsing redux
Using redux
 
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheet
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheetDo something in 5 with gas 4- Get your analytics profiles to a spreadsheet
Do something in 5 with gas 4- Get your analytics profiles to a spreadsheet
 
Do something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing appDo something in 5 with gas 3-simple invoicing app
Do something in 5 with gas 3-simple invoicing app
 
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
Do something useful in Apps Script 5. Get your analytics pageviews to a sprea...
 
Academy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & ToolingAcademy PRO: React JS. Redux & Tooling
Academy PRO: React JS. Redux & Tooling
 
React.js and Redux overview
React.js and Redux overviewReact.js and Redux overview
React.js and Redux overview
 
React 101
React 101React 101
React 101
 
Redux Universal
Redux UniversalRedux Universal
Redux Universal
 
React и redux
React и reduxReact и redux
React и redux
 
VBA API for scriptDB primer
VBA API for scriptDB primerVBA API for scriptDB primer
VBA API for scriptDB primer
 
Better React state management with Redux
Better React state management with ReduxBetter React state management with Redux
Better React state management with Redux
 
Workshop 22: React-Redux Middleware
Workshop 22: React-Redux MiddlewareWorkshop 22: React-Redux Middleware
Workshop 22: React-Redux Middleware
 
Redux js
Redux jsRedux js
Redux js
 
React outbox
React outboxReact outbox
React outbox
 
ASP.NET Internals
ASP.NET InternalsASP.NET Internals
ASP.NET Internals
 
React JS and Redux
React JS and ReduxReact JS and Redux
React JS and Redux
 
Dicoding Developer Coaching #32: Android | Reactive Programming dengan RxJava...
Dicoding Developer Coaching #32: Android | Reactive Programming dengan RxJava...Dicoding Developer Coaching #32: Android | Reactive Programming dengan RxJava...
Dicoding Developer Coaching #32: Android | Reactive Programming dengan RxJava...
 

Similar to Controller

Backbone.js
Backbone.jsBackbone.js
Backbone.js
Knoldus Inc.
 
Learn Drupal 8 Render Pipeline
Learn Drupal 8 Render PipelineLearn Drupal 8 Render Pipeline
Learn Drupal 8 Render Pipeline
Zyxware Technologies
 
Behavioral pattern 4
Behavioral pattern 4Behavioral pattern 4
Behavioral pattern 4
Naga Muruga
 
WPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA AustriaWPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA Austria
Rainer Stropek
 
Angular custom directives
Angular custom directivesAngular custom directives
Angular custom directivesAlexe Bogdan
 
AngularJS.part1
AngularJS.part1AngularJS.part1
AngularJS.part1
Andrey Kolodnitsky
 
Coldbox developer training – session 5
Coldbox developer training – session 5Coldbox developer training – session 5
Coldbox developer training – session 5Billie Berzinskas
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
zeeshanhanif
 
ASP .net MVC
ASP .net MVCASP .net MVC
ASP .net MVC
Divya Sharma
 
SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015
Pushkar Chivate
 
AngularJs-training
AngularJs-trainingAngularJs-training
AngularJs-training
Pratchaya Suputsopon
 
PHP MVC
PHP MVCPHP MVC
Patterns Are Good For Managers
Patterns Are Good For ManagersPatterns Are Good For Managers
Patterns Are Good For Managers
AgileThought
 
The state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon DublinThe state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon Dublin
Nida Ismail Shah
 
Controller in AngularJS
Controller in AngularJSController in AngularJS
Controller in AngularJS
Brajesh Yadav
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
Omnia Helmi
 
GradleFX
GradleFXGradleFX

Similar to Controller (20)

Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Learn Drupal 8 Render Pipeline
Learn Drupal 8 Render PipelineLearn Drupal 8 Render Pipeline
Learn Drupal 8 Render Pipeline
 
Behavioral pattern 4
Behavioral pattern 4Behavioral pattern 4
Behavioral pattern 4
 
Django
DjangoDjango
Django
 
WPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA AustriaWPF and Prism 4.1 Workshop at BASTA Austria
WPF and Prism 4.1 Workshop at BASTA Austria
 
Angular custom directives
Angular custom directivesAngular custom directives
Angular custom directives
 
AngularJS.part1
AngularJS.part1AngularJS.part1
AngularJS.part1
 
Coldbox developer training – session 5
Coldbox developer training – session 5Coldbox developer training – session 5
Coldbox developer training – session 5
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
 
ASP .net MVC
ASP .net MVCASP .net MVC
ASP .net MVC
 
SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015
 
AngularJs-training
AngularJs-trainingAngularJs-training
AngularJs-training
 
Backbone Basics with Examples
Backbone Basics with ExamplesBackbone Basics with Examples
Backbone Basics with Examples
 
PHP MVC
PHP MVCPHP MVC
PHP MVC
 
Patterns Are Good For Managers
Patterns Are Good For ManagersPatterns Are Good For Managers
Patterns Are Good For Managers
 
The state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon DublinThe state of hooking into Drupal - DrupalCon Dublin
The state of hooking into Drupal - DrupalCon Dublin
 
Controller in AngularJS
Controller in AngularJSController in AngularJS
Controller in AngularJS
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Django design-patterns
Django design-patternsDjango design-patterns
Django design-patterns
 
GradleFX
GradleFXGradleFX
GradleFX
 

More from Vijay Shukla

Introduction of webpack 4
Introduction of webpack 4Introduction of webpack 4
Introduction of webpack 4
Vijay Shukla
 
Preview of Groovy 3
Preview of Groovy 3Preview of Groovy 3
Preview of Groovy 3
Vijay Shukla
 
Jython
JythonJython
Jython
Vijay Shukla
 
Groovy closures
Groovy closuresGroovy closures
Groovy closures
Vijay Shukla
 
Groovy
GroovyGroovy
Groovy
Vijay Shukla
 
Grails services
Grails servicesGrails services
Grails services
Vijay Shukla
 
Grails plugin
Grails pluginGrails plugin
Grails plugin
Vijay Shukla
 
Grails domain
Grails domainGrails domain
Grails domain
Vijay Shukla
 
Grails custom tag lib
Grails custom tag libGrails custom tag lib
Grails custom tag lib
Vijay Shukla
 
Grails
GrailsGrails
Grails
Vijay Shukla
 
Gorm
GormGorm
Config BuildConfig
Config BuildConfigConfig BuildConfig
Config BuildConfig
Vijay Shukla
 
Command object
Command objectCommand object
Command object
Vijay Shukla
 
Boot strap.groovy
Boot strap.groovyBoot strap.groovy
Boot strap.groovy
Vijay Shukla
 
Vertx
VertxVertx
Custom plugin
Custom pluginCustom plugin
Custom plugin
Vijay Shukla
 
Spring security
Spring securitySpring security
Spring security
Vijay Shukla
 
REST
RESTREST
Config/BuildConfig
Config/BuildConfigConfig/BuildConfig
Config/BuildConfig
Vijay Shukla
 
GORM
GORMGORM

More from Vijay Shukla (20)

Introduction of webpack 4
Introduction of webpack 4Introduction of webpack 4
Introduction of webpack 4
 
Preview of Groovy 3
Preview of Groovy 3Preview of Groovy 3
Preview of Groovy 3
 
Jython
JythonJython
Jython
 
Groovy closures
Groovy closuresGroovy closures
Groovy closures
 
Groovy
GroovyGroovy
Groovy
 
Grails services
Grails servicesGrails services
Grails services
 
Grails plugin
Grails pluginGrails plugin
Grails plugin
 
Grails domain
Grails domainGrails domain
Grails domain
 
Grails custom tag lib
Grails custom tag libGrails custom tag lib
Grails custom tag lib
 
Grails
GrailsGrails
Grails
 
Gorm
GormGorm
Gorm
 
Config BuildConfig
Config BuildConfigConfig BuildConfig
Config BuildConfig
 
Command object
Command objectCommand object
Command object
 
Boot strap.groovy
Boot strap.groovyBoot strap.groovy
Boot strap.groovy
 
Vertx
VertxVertx
Vertx
 
Custom plugin
Custom pluginCustom plugin
Custom plugin
 
Spring security
Spring securitySpring security
Spring security
 
REST
RESTREST
REST
 
Config/BuildConfig
Config/BuildConfigConfig/BuildConfig
Config/BuildConfig
 
GORM
GORMGORM
GORM
 

Recently uploaded

RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 

Recently uploaded (20)

RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 

Controller

  • 2. Controllers A controller handles requests and creates or prepares the response. A controller can generate the response directly or delegate to a view. Destination folder: grails-app/controllers directory
  • 3. Create a controller Command : grails create-controller book package myapp class BookController { def index() { } }
  • 4. Structure of controller class BookController { def list() { // do controller logic // create model return model } }
  • 5. Closure vs controller Earlier versions of Grails actions were implemented with Closures. This is still supported, but the preferred approach is to use methods. Leveraging methods instead of Closure properties has some advantages: 1. Memory efficient 2. Allow use of stateless controllers (singleton scope) 3. You can override actions from subclasses and call the overridden superclass method with super.actionName()
  • 6. Default action rules If there is only one action, it's the default If you have an action named index, it's the default Alternatively you can set it explicitly with the defaultAction property: static defaultAction = "list"
  • 7. Scopes available in controllers servletContext - Also known as application scope, this scope lets you share state across the entire web application. The servletContext is an instance of ServletContext session - The session allows associating state with a given user and typically uses cookies to associate a session with a client. The session object is an instance of HttpSession request - The request object allows the storage of objects for the current request only. The request object is an instance of HttpServletRequest params - Mutable map of incoming request query string or POST parameters flash - the concept of flash scope as a temporary store to make attributes available for this request and the next request only. Afterwards the attributes are cleared. This is useful for setting a message directly before redirecting.
  • 9. Scoped Controller prototype (default) - A new controller will be created for each request (recommended for actions as Closure properties) session - One controller is created for the scope of a user session singleton - Only one instance of the controller ever exists (recommended for actions as methods) To enable one of the scopes, add a static scope property to your class with one of the valid scope values listed above, for example static scope = "singleton" You can define the default strategy under in Config.groovy with the grails.controllers.defaultScope key, for example: grails.controllers.defaultScope = "singleton"
  • 10. Redirect with controller // Call the login action within the same class redirect(action: login) // Also redirects to the index action in the home controller redirect(controller: 'home', action: 'index') // Redirect to an explicit URI redirect(uri: "/login.html") // Redirect to a URL redirect(url: "http://grails.org") redirect(action: 'myaction', params: [myparam: "myvalue"])
  • 11. Render with controller Object for example: def theShining = new Book(title: 'The Shining', author: 'Stephen King') render(view: "viewName", model: [book: theShining]) render(template: "book", model: [book: theShining])
  • 12. @ annotation with controller package sample import grails.plugins.springsecurity.Secured class ScreenController { def publicPage() { render "This is a public page" } @Secured(['ROLE_COMMON']) def commonPage() { render "This is a common role page" } } commonPage - only user with ROLE_COMMON role can access this page.
  • 13. URLs The first part of the URL is the application name, or Application Context Root. The next part of the URL is the controller name. Notice that the Controller part of UserController gets dropped off, and the first letter is changed to lowercase. After the controller name, you’ll see an optional action name. This name corresponds directly to the action in the Controller.
  • 14. Controller Interceptors Before Interception The beforeInterceptor intercepts processing before the action is executed. If it returns false then the intercepted action will not be executed. After Interception Use the afterInterceptor property to define an interceptor that is executed after an action