SlideShare a Scribd company logo
Grails and Ajax
Grails & Ajax
1. What isAjax?
2. Grails inbuiltsupport for Ajax
3. Some Cute examples
4. Questions
3
Session Agenda
● The technology was originally developed by Microsoft to power a web-
based version of itsOutlook e-mail software. Microsoft implemented Ajax as
an ActiveX control that could be used by its browser, Internet Explorer, and
be called from JavaScript to perform asynchronous browser requests
● The advantage of the approach isthat the browser doesn’t have to refresh
the entire page to interact with the server
● We have to write browser-specific code to load XMLHttpRequest object
● Grails tags did thisthingautomatically
● Writing Browser Specific JavaScript code can become rather repetitive and
tedious. Fortunately, there are Ajax frameworks that encapsulate much of this
logic, ranging from the simple (such as Prototype) to the comprehensive
(such asDojo)
4
AJAX
The browser calls some JavaScript, which in turn creates the XMLHttpRequest
object that isable to make the remote call. When the remote call has been
made, the XMLHttpRequest object then invokes the callback (in this case the
processRequest function), which in turn displays the alert
Ajax Flow
5
Grails uses prototype library to provide support for ajax
Include this line on the page where you are using ajax
<g:javascript library="prototype"/>
6
Grails Support For Ajax
Some of the basic tags are as follows:
RemoteLink
– <g:remoteLink action="showTime"update="time">
• Show thetime!
</g:remoteLink>
•
<divid="time">
• </div>
– def showTime ={
– render "Thetime is${newDate()}"
– }
– Remote link calls an action at server and updates a div tag on
success/failure
7
<g:formRemote
name="loginForm"
url="[controller:'user',action:'login']"
update="loginBox">
...
</g:formRemote>
<divid="loginBox">
</div>
def loginBox ={
//process formhere
render "Success"
}
Alternatively you can use submitToRemote tag as well
8
Form Remote
<select
onchange="${remoteFunction(action:'bookbyname',update:[success:'great'
, failure:'ohno'], params:''bookName=' +this.value')}">
– <option>first</option>
– <option>second</option>
– </select>
– Creates a remote javascript function that can be assigned to a DOM
event to call the remote method
9
Remote Function
<g:formRemoteaction="login"
before="setDefaultValue(this);"
update="loginBox"
name="loginForm">
...</g:formRemote>
<divid="loginBox"></div>
<script type=”text/javascript”>
function setDefaultValue(x){
//somecode here
}
</script>
def loginBox ={
//process formhere
render "Success"
}
10
Executing Code Before and After a Call
<g:formRemote url="[controller:'user',action:'login']"
onLoading="showProgress();" onComplete="hideProgress();"
update="loginBox" name="loginForm">
...
</g:formRemote>
ListOfevents
onSuccess : Called when the remote call issuccessful
onFailure : Called when the remote call begins to load the response
onLoaded :Called when the remote call has loaded the response
onComplete :Called when the response has been received and any
updates arecompleted
onERROR_CODE : Called for specific error codes such as on404
11
Handling Events
Grails provides an extremely useful tag to help implement the search feature—
the <g:remoteField> tag. As you might guess from the name, <g:remoteField> is
a text field that sends itsvalue to the server whenever it changes..
<divid="searchBox">
Instant Search:<g:remoteField
name="searchBox"
update="musicPanel"
paramName="q"
url="[control er:'store', action:'search']"/>
</div>
12
Ajax-Enabled Form Fields
OnClicking a link you gotta fetch a template to update a div
onclick="fetchTemplate('$createLink(action:'todo',controller:'dashBoard')}',
this.id);"
function fetchTemplate(url, id) {
jQuery.get(url, {ajax: 'true'}, function(todo){
jQuery('#todoTab').html(todo);
});
}
def todo ={
– //do someprocessing
// render atemplate
render (template:'someTemplate')
}
13
Some Cute Codes
Getting a JSONresponse
Ajax–like File Upload . (In-House researchproject)
14
Some Cute Codes
• Given the number of small snippets of code that get rendered, it wil come as
little surprise that badly designed Ajax applications have to deal with a
significantly larger number ofrequests
• The firstthing to remember isthat an Ajax call isa remote network call and
therefore expensive. Ifyou have developed with EJB,you will recall some of
the patterns used to optimizeEJB remote method calls. Things such as the
Data Transfer Object (DTO) are equally applicable in the Ajax world
• Fundamentally, the DTO pattern serves as a mechanism for batching
operations into a single call and passing enough state to the server for
several operations to be executed at once. This pattern can be equally
effective in Ajax, given that it isbetter to do one call that transmits a lot of
information than a dozen small ones
15
A Note on Ajax and Performance
• Caching isprobably the most important technique in Ajax development
and,where possible, should be exploited to optimize communications
with theserver
• Debugging istough (yikes....)
16
A Note on Ajax and Performance
1.www.grails.org
2.DGG
17
References
Contact us
Our Office
Client
Location
Click Here To Know More!
Have more queries on Grails?
Talk to our GRAILS experts
Now!
Talk To Our Experts
Here's how the world's
biggest Grails team is
building enterprise
applications on Grails!

More Related Content

What's hot (20)

PDF
React Js Simplified
Sunil Yadav
 
PDF
Introduction to JavaScript
Bryan Basham
 
KEY
Prueba De Aplicaciones Web con Selenium 2 y WebDriver
David Gómez García
 
PPTX
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
PDF
React & GraphQL
Nikolas Burk
 
PPT
JavaScript & Dom Manipulation
Mohammed Arif
 
PDF
Introduction to React JS
Bethmi Gunasekara
 
PDF
react-js-notes-for-professionals-book.pdf
AdilKhalki1
 
PDF
jQuery for beginners
Arulmurugan Rajaraman
 
PPTX
Jsf presentation
Ashish Gupta
 
PPT
jQuery
Mohammed Arif
 
PDF
Workshop 21: React Router
Visual Engineering
 
PDF
VueJS: The Simple Revolution
Rafael Casuso Romate
 
PDF
Ebook học Javascript cơ bản tới nâng cao
Trung Thanh Nguyen
 
PPTX
Sharing Data Between Angular Components
Squash Apps Pvt Ltd
 
PPT
Introduction to HTML5
IT Geeks
 
PPTX
React workshop
Imran Sayed
 
PPTX
HTML 5 Canvas & SVG
Ofir's Fridman
 
PPT
Javascript by geetanjali
Geetanjali Bhosale
 
PPTX
Introduction to React JS for beginners | Namespace IT
namespaceit
 
React Js Simplified
Sunil Yadav
 
Introduction to JavaScript
Bryan Basham
 
Prueba De Aplicaciones Web con Selenium 2 y WebDriver
David Gómez García
 
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
React & GraphQL
Nikolas Burk
 
JavaScript & Dom Manipulation
Mohammed Arif
 
Introduction to React JS
Bethmi Gunasekara
 
react-js-notes-for-professionals-book.pdf
AdilKhalki1
 
jQuery for beginners
Arulmurugan Rajaraman
 
Jsf presentation
Ashish Gupta
 
Workshop 21: React Router
Visual Engineering
 
VueJS: The Simple Revolution
Rafael Casuso Romate
 
Ebook học Javascript cơ bản tới nâng cao
Trung Thanh Nguyen
 
Sharing Data Between Angular Components
Squash Apps Pvt Ltd
 
Introduction to HTML5
IT Geeks
 
React workshop
Imran Sayed
 
HTML 5 Canvas & SVG
Ofir's Fridman
 
Javascript by geetanjali
Geetanjali Bhosale
 
Introduction to React JS for beginners | Namespace IT
namespaceit
 

Viewers also liked (20)

PPTX
Object Oriented JavaScript - II
TO THE NEW | Technology
 
PPTX
Lesson10 preterit
Lauren
 
DOCX
Annotating images-animation
sathma
 
PPT
Het nieuwe werven
Alliander
 
KEY
Final presentation
marshall
 
PPS
Murphy
Rcabellocaja
 
PPTX
Office 365 voor het onderwijs
IT-Workz
 
DOCX
Cell block 33 script
sathma
 
PPTX
The body
Lauren
 
PPTX
Winning and nurturing leads in a web 2.0 environment; ShipServ and why conten...
John Watton
 
PPT
Presentation of medivel
sathma
 
DOC
Traditional mural vs non traditional mural
sathma
 
PDF
FUKUYAMA BASE WORKSHOP Vol18 Theme
noteproject
 
PPTX
Blogging as part of your content marketing strategy
John Watton
 
PDF
Design for Motivation - Intrinsic and extrinsic motivation in design
Thijs de Vries
 
PDF
gasdj456djkdi3353452
cephas3
 
PPTX
Campaigns are dead - long live content.
John Watton
 
TXT
Pontos para criar_instancia_data guard_11g
Leandro Santos
 
PPTX
3 different methods to publicise our presentation
sathma
 
PPTX
Lesson8 presentverbs
Lauren
 
Object Oriented JavaScript - II
TO THE NEW | Technology
 
Lesson10 preterit
Lauren
 
Annotating images-animation
sathma
 
Het nieuwe werven
Alliander
 
Final presentation
marshall
 
Murphy
Rcabellocaja
 
Office 365 voor het onderwijs
IT-Workz
 
Cell block 33 script
sathma
 
The body
Lauren
 
Winning and nurturing leads in a web 2.0 environment; ShipServ and why conten...
John Watton
 
Presentation of medivel
sathma
 
Traditional mural vs non traditional mural
sathma
 
FUKUYAMA BASE WORKSHOP Vol18 Theme
noteproject
 
Blogging as part of your content marketing strategy
John Watton
 
Design for Motivation - Intrinsic and extrinsic motivation in design
Thijs de Vries
 
gasdj456djkdi3353452
cephas3
 
Campaigns are dead - long live content.
John Watton
 
Pontos para criar_instancia_data guard_11g
Leandro Santos
 
3 different methods to publicise our presentation
sathma
 
Lesson8 presentverbs
Lauren
 
Ad

Similar to Grails and Ajax (20)

PDF
Node azure
Emanuele DelBono
 
PDF
Docker Logging and analysing with Elastic Stack
Jakub Hajek
 
PDF
Docker Logging and analysing with Elastic Stack - Jakub Hajek
PROIDEA
 
PPT
Mobile webapplication development
Ganesh Gembali
 
PPTX
concept of server-side JavaScript / JS Framework: NODEJS
Kongu Engineering College, Perundurai, Erode
 
PPT
Rob Tweed :: Ajax and the Impact on Caché and Similar Technologies
george.james
 
PPT
Ajax Performance
kaven yan
 
PPTX
introduction to node.js
orkaplan
 
PDF
Introduction to REST API with Node.js
Yoann Gotthilf
 
PPTX
JavaScripts & jQuery
Asanka Indrajith
 
PDF
Dwr
Suhas Kamble
 
PPTX
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
Chalermpon Areepong
 
PDF
Zepto and the rise of the JavaScript Micro-Frameworks
Thomas Fuchs
 
PPT
Using Ajax In Domino Web Applications
dominion
 
PDF
ITI006En-AJAX
Huibert Aalbers
 
PDF
Google app-engine-cloudcamplagos2011
Opevel
 
PPT
Ajax with DWR
gouthamrv
 
PDF
Porting Rails Apps to High Availability Systems
Marcelo Pinheiro
 
PPT
Intoduction to Play Framework
Knoldus Inc.
 
PDF
JavaFX Enterprise (JavaOne 2014)
Hendrik Ebbers
 
Node azure
Emanuele DelBono
 
Docker Logging and analysing with Elastic Stack
Jakub Hajek
 
Docker Logging and analysing with Elastic Stack - Jakub Hajek
PROIDEA
 
Mobile webapplication development
Ganesh Gembali
 
concept of server-side JavaScript / JS Framework: NODEJS
Kongu Engineering College, Perundurai, Erode
 
Rob Tweed :: Ajax and the Impact on Caché and Similar Technologies
george.james
 
Ajax Performance
kaven yan
 
introduction to node.js
orkaplan
 
Introduction to REST API with Node.js
Yoann Gotthilf
 
JavaScripts & jQuery
Asanka Indrajith
 
ZZ BC#7.5 asp.net mvc practice and guideline refresh!
Chalermpon Areepong
 
Zepto and the rise of the JavaScript Micro-Frameworks
Thomas Fuchs
 
Using Ajax In Domino Web Applications
dominion
 
ITI006En-AJAX
Huibert Aalbers
 
Google app-engine-cloudcamplagos2011
Opevel
 
Ajax with DWR
gouthamrv
 
Porting Rails Apps to High Availability Systems
Marcelo Pinheiro
 
Intoduction to Play Framework
Knoldus Inc.
 
JavaFX Enterprise (JavaOne 2014)
Hendrik Ebbers
 
Ad

More from TO THE NEW | Technology (20)

PDF
10 Best Node.js Practices you Need to Know!
TO THE NEW | Technology
 
PDF
10 Pragmatic UX techniques for building smarter products:
TO THE NEW | Technology
 
PDF
12 Key points which make Swift more effective than Objective C
TO THE NEW | Technology
 
PDF
Gulp - The Streaming Build System
TO THE NEW | Technology
 
PPTX
Grails Spring Boot
TO THE NEW | Technology
 
PPTX
AWS Elastic Beanstalk
TO THE NEW | Technology
 
PPT
Content migration to AEM
TO THE NEW | Technology
 
PPTX
AWS CodeDeploy
TO THE NEW | Technology
 
PPTX
Big Data Expertise
TO THE NEW | Technology
 
PPTX
An introduction to Object Oriented JavaScript
TO THE NEW | Technology
 
PPTX
MongoDb and NoSQL
TO THE NEW | Technology
 
PPTX
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software
TO THE NEW | Technology
 
PPTX
MongoDB using Grails plugin by puneet behl
TO THE NEW | Technology
 
PPTX
Cloud Formation
TO THE NEW | Technology
 
PPTX
BigData Search Simplified with ElasticSearch
TO THE NEW | Technology
 
DOCX
JULY IN GRAILS
TO THE NEW | Technology
 
PPTX
Grails Spock Testing
TO THE NEW | Technology
 
PPTX
Getting groovier-with-vertx
TO THE NEW | Technology
 
PPTX
Introduction to Kanban
TO THE NEW | Technology
 
PPTX
Introduction to Heroku
TO THE NEW | Technology
 
10 Best Node.js Practices you Need to Know!
TO THE NEW | Technology
 
10 Pragmatic UX techniques for building smarter products:
TO THE NEW | Technology
 
12 Key points which make Swift more effective than Objective C
TO THE NEW | Technology
 
Gulp - The Streaming Build System
TO THE NEW | Technology
 
Grails Spring Boot
TO THE NEW | Technology
 
AWS Elastic Beanstalk
TO THE NEW | Technology
 
Content migration to AEM
TO THE NEW | Technology
 
AWS CodeDeploy
TO THE NEW | Technology
 
Big Data Expertise
TO THE NEW | Technology
 
An introduction to Object Oriented JavaScript
TO THE NEW | Technology
 
MongoDb and NoSQL
TO THE NEW | Technology
 
(AWS) Auto Scaling : Evening Session by Amazon and IntelliGrape Software
TO THE NEW | Technology
 
MongoDB using Grails plugin by puneet behl
TO THE NEW | Technology
 
Cloud Formation
TO THE NEW | Technology
 
BigData Search Simplified with ElasticSearch
TO THE NEW | Technology
 
JULY IN GRAILS
TO THE NEW | Technology
 
Grails Spock Testing
TO THE NEW | Technology
 
Getting groovier-with-vertx
TO THE NEW | Technology
 
Introduction to Kanban
TO THE NEW | Technology
 
Introduction to Heroku
TO THE NEW | Technology
 

Recently uploaded (20)

PDF
Learn Computer Forensics, Second Edition
AnuraShantha7
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
Learn Computer Forensics, Second Edition
AnuraShantha7
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 

Grails and Ajax

  • 3. 1. What isAjax? 2. Grails inbuiltsupport for Ajax 3. Some Cute examples 4. Questions 3 Session Agenda
  • 4. ● The technology was originally developed by Microsoft to power a web- based version of itsOutlook e-mail software. Microsoft implemented Ajax as an ActiveX control that could be used by its browser, Internet Explorer, and be called from JavaScript to perform asynchronous browser requests ● The advantage of the approach isthat the browser doesn’t have to refresh the entire page to interact with the server ● We have to write browser-specific code to load XMLHttpRequest object ● Grails tags did thisthingautomatically ● Writing Browser Specific JavaScript code can become rather repetitive and tedious. Fortunately, there are Ajax frameworks that encapsulate much of this logic, ranging from the simple (such as Prototype) to the comprehensive (such asDojo) 4 AJAX
  • 5. The browser calls some JavaScript, which in turn creates the XMLHttpRequest object that isable to make the remote call. When the remote call has been made, the XMLHttpRequest object then invokes the callback (in this case the processRequest function), which in turn displays the alert Ajax Flow 5
  • 6. Grails uses prototype library to provide support for ajax Include this line on the page where you are using ajax <g:javascript library="prototype"/> 6 Grails Support For Ajax
  • 7. Some of the basic tags are as follows: RemoteLink – <g:remoteLink action="showTime"update="time"> • Show thetime! </g:remoteLink> • <divid="time"> • </div> – def showTime ={ – render "Thetime is${newDate()}" – } – Remote link calls an action at server and updates a div tag on success/failure 7
  • 9. <select onchange="${remoteFunction(action:'bookbyname',update:[success:'great' , failure:'ohno'], params:''bookName=' +this.value')}"> – <option>first</option> – <option>second</option> – </select> – Creates a remote javascript function that can be assigned to a DOM event to call the remote method 9 Remote Function
  • 11. <g:formRemote url="[controller:'user',action:'login']" onLoading="showProgress();" onComplete="hideProgress();" update="loginBox" name="loginForm"> ... </g:formRemote> ListOfevents onSuccess : Called when the remote call issuccessful onFailure : Called when the remote call begins to load the response onLoaded :Called when the remote call has loaded the response onComplete :Called when the response has been received and any updates arecompleted onERROR_CODE : Called for specific error codes such as on404 11 Handling Events
  • 12. Grails provides an extremely useful tag to help implement the search feature— the <g:remoteField> tag. As you might guess from the name, <g:remoteField> is a text field that sends itsvalue to the server whenever it changes.. <divid="searchBox"> Instant Search:<g:remoteField name="searchBox" update="musicPanel" paramName="q" url="[control er:'store', action:'search']"/> </div> 12 Ajax-Enabled Form Fields
  • 13. OnClicking a link you gotta fetch a template to update a div onclick="fetchTemplate('$createLink(action:'todo',controller:'dashBoard')}', this.id);" function fetchTemplate(url, id) { jQuery.get(url, {ajax: 'true'}, function(todo){ jQuery('#todoTab').html(todo); }); } def todo ={ – //do someprocessing // render atemplate render (template:'someTemplate') } 13 Some Cute Codes
  • 14. Getting a JSONresponse Ajax–like File Upload . (In-House researchproject) 14 Some Cute Codes
  • 15. • Given the number of small snippets of code that get rendered, it wil come as little surprise that badly designed Ajax applications have to deal with a significantly larger number ofrequests • The firstthing to remember isthat an Ajax call isa remote network call and therefore expensive. Ifyou have developed with EJB,you will recall some of the patterns used to optimizeEJB remote method calls. Things such as the Data Transfer Object (DTO) are equally applicable in the Ajax world • Fundamentally, the DTO pattern serves as a mechanism for batching operations into a single call and passing enough state to the server for several operations to be executed at once. This pattern can be equally effective in Ajax, given that it isbetter to do one call that transmits a lot of information than a dozen small ones 15 A Note on Ajax and Performance
  • 16. • Caching isprobably the most important technique in Ajax development and,where possible, should be exploited to optimize communications with theserver • Debugging istough (yikes....) 16 A Note on Ajax and Performance
  • 18. Contact us Our Office Client Location Click Here To Know More! Have more queries on Grails? Talk to our GRAILS experts Now! Talk To Our Experts Here's how the world's biggest Grails team is building enterprise applications on Grails!