(Quick Reference)
link
Purpose
Adds a
GrailsButton component to the parent container.
Examples
Example controller for an application called "shop":
class BookVaadinController {
static defaultAction = "list" def list() {
[books: Book.list(params)]
} def show() {
[book: Book.get(params.id)]
} def edit() {
[book: params.instance]
}
}
Example usages for above controller:
<v:link action="show" id="1">Book 1</v:link><v:link action="show" id="${currentBook.id}">${currentBook.name}</v:link><v:link action="edit" instance="${currentBook}">${currentBook.name}</v:link><v:link controller="book">Book Home</v:link><v:link controller="book" action="list">Book List</v:link><v:link action="list" params="[sort: 'title', order: 'asc',
author: currentBook.author]">
Book List
</v:link><v:link fragment="#book/list">Book List</v:link>/* ONCLICK */<v:link onclick="${{it.caption = new Date()}}">Click Here!</v:link>/** ICON */// In web-app/images
<v:link icon="${resource(file:'images/spinner.gif')}">Loading</v:link>// In web-app/VAADIN/themes/[activetheme]/images
<v:link icon="images/spinner.gif">Loading</v:link>/** STYLING */// Use image as button (i.e. no button styling)
<v:link class="transparent" icon="images/spinner.gif"/>// Make button look like HTML anchor
<v:link class="link">Hello World!</v:link>
When calling this tag as a GSP method, use the
createLink
method as follows:
${v.createLink(action:'list',controller:'book',caption:'Book List')}
Description
Body
- Used as the
caption
of the button, unless overridden by the caption
attribute.
Attributes
Specific
caption
(optional) The caption of the button. Overrides the value in the body.
icon
(optional) The button icon. Can be specified as a Vaadin Resource, or as a String path to the resource. If the path starts with /
or contains ://
, it is treated as a URL; otherwise, it is treated as a path relative to the directory of the Vaadin application's active theme.
action
(optional) The action of the Vaadin controller to link to. If omitted, defaults to 'index'
controller
(optional) The Vaadin controller to link to. If omitted, defaults to the controller of the current 'request'.
params
(optional) The params to use when executing the Vaadin controller.
id
(optional) The id parameter to use in the link.
instance
(optional) The domain class instance parameter to use in the link.
fragment
(optional) The fragment to link to, for example #book/list
onclick
(optional) Similar to the HTML onclick attribute. Here, the attribute takes a closure, in which it
is the enclosing button component. If the closure returns false, the link is not followed. The closure can trigger the link to be followed later with it.dispatch()
.
General
var
(optional) Uses Grails's set tag to set the value of the specified variable to be this component.
class
(optional) The CSS class name to add to the component using the addStyleName() method
sizeUndefined
(optional) Calls setSizeUndefined() on the component. (Attribute value is ignored)
sizeFull
(optional) Calls setSizeFull() on the component. (Attribute value is ignored)
location
(optional) The location slot in the parent container to which this component should be added.
wrapperClass
, wrapperStyle
(optional) Special styling for wrapper <div>
.
See Vaadin Button API docs for full list of allowed attributes for a button.
CSS Styles
link
Style the button like an HTML anchor tag
transparent
Style the button without any border, background or padding.
Special Use Cases
Confirm on Delete
A tag method
v.confirm
is available for use in the
onclick
attribute. This displays a popup
window with OK and Cancel buttons. Typically, it is used to prompt the user to confirm before
deleting a record. It is intended to mimic Javascript's
confirm()
function.
<v:link action="delete" id="1" onclick="${v.confirm(message:message(
code:'default.button.delete.confirm.message', default:'Are you sure?'))}">
Delete
</v:link>
Commit Form on Save
A tag method
v.commit
is available for use in the
onclick
attribute. This commits the
Vaadin
Form component before following the link.
Typically it is used when clicking the Submit-type button on form, to write the form's changes
through to the domain class instance, before that instance is then written to the database.
<v:form var="myForm">
<v:field name="author">Author</v:field>
</v:form><v:link action="save" id="1" onclick="${v.commit(form:'myForm')}">
Save
</v:link>