(Quick Reference)
remoteLink
The remoteLink tag and other Ajax related tags have been deprecated and will be removed from a future version of Grails. Applications may provide their own Ajax tags and/or Javascript plugins may provide Ajax tags of their own.
Purpose
Creates a link that uses Ajax to call a remote function when clicked
Examples
Example controller for an application called
shop
:
class BookController { def list() {
[books: Book.list(params)]
} def show() {
[book: Book.get(params.id)]
} def bookByName() {
[book: Book.findByName(params.bookName)]
}
}
Example usages for above controller:
<g:remoteLink action="show" id="1">Test 1</g:remoteLink><g:remoteLink action="show" id="1" update="[success:'success',failure:'error']"
on404="alert('not found');">Test 2</g:remoteLink><g:remoteLink action="show" id="1" update="success"
onLoading="showSpinner();">Test 3</g:remoteLink><g:remoteLink action="show" id="1" update="success"
params="[sortBy:'name',offset:offset]">Test 4</g:remoteLink><g:remoteLink action="show" id="1" update="success"
before="if(!confirm('Are you sure?')) return false">Test 5</g:remoteLink>
As a method call in GSP:
my link = <%= remoteLink(action: 'show', id: 1,
update: 'success', onFailure: 'showError();')
{ "this is the link body" } %>
Description
This tag creates an HTML link to a controller action that generates an AJAX request when it is clicked. The exact Javascript used to fire off the AJAX request depends on which Javascript library is used. This tag also requires the use of either the <g:
javascript/> or <g:
setProvider/> tags. See the
AJAX section of the user guide to find out more.
Attributes
action
(optional) - the name of the action to use in the link; if not specified the default action will be linked
controller
(optional) - the name of the controller to use in the link; if not specified the current controller will be linked
id
(optional) - The id to use in the link
fragment
(optional) - The link fragment (often called anchor tag) to use
mapping
(optional) - The named URL mapping to use to rewrite the link
params
(optional) - a Map containing request parameters
update
(optional) - Either a Map containing the elements to update for 'success' or 'failure' states, or a string with the element id to update, in which case failure events would be ignored
before
(optional) - The JavaScript function to call before the remote function call. A semi-colon is automatically added so you don't have to provide one yourself in this string.
after
(optional) - The JavaScript function to call after the remote function call. A semi-colon is automatically added so you don't have to provide one yourself in this string.
asynchronous
(optional) - Whether to do the call asynchronously (defaults to true)
method
(optional) - The method to use the execute the call (defaults to POST)
Events
onSuccess
(optional) - The JavaScript function to call if successful
onFailure
(optional) - The JavaScript function to call if the call fails
on_ERROR_CODE
(optional) - The JavaScript function to call to handle the specified error code (eg on404="alert('not found!')"). With Prototype, this prevents execution of onSuccess
and onFailure
.
onUninitialized
(optional) - The JavaScript function to call if Ajax fails to initialise
onLoading
(optional) - The JavaScript function to call when the remote function loads the response
onLoaded
(optional) - The JavaScript function to call when the remote function completes loading the response
onComplete
(optional) - The JavaScript function to call when the remote function completes, including any updates
Source