(Quick Reference)

7 UI Extensions - Reference Documentation

Authors: Marc Palmer (marc@grailsrocks.com), Stéphane Maldini (smaldini@vmware.com)

Version: 1.0.RC3

7 UI Extensions

Several simple UI Extensions are included in platform-core.

The tags supplied make it trivial to render links to controllers and actions using i18n messages, display messages to the end user, and render buttons and labels in i18n friendly ways.

7.1 Tags

Linking tags

The smartLink tag renders links for controllers and actions, automatically working out the text of the link using i18n.

<%-- Link to default action of BooksController --%>
<p:smartLink controller="books"/>

<%-- Link to list action of current controller --%>
<p:smartLink action="list"/>

These will use i18n messages located by convention of the form: action.controllerName.actionName

Label tag

The label tag will render a <label> with the text optionally loaded from i18n:

<p:label text="field.user.name"/>

See label for full details of the attributes, which include passing arguments to the i18n message.

Button tag

The button tag will render a text-based button using either a <button>, <input type="submit"> or <a> tag, with the text optionally loaded from i18n:

<p:button text="button.save"/>

See button for full details of the attributes, which include setting the kind of button rendered and passing arguments to the i18n message.

Display message tag

The displayMessage tag works with the displayMessage and displayFlashMessage controller methods to make it easy to render messages to the user in a uniform way.

<p:displayMessage/>

See displayMessage for full details of the attributes and the displayMessage and displayFlashMessage controller methods.

The tag will render both request and flash messages, and wraps them in a div with CSS classes according to the type of message.

Branding tags

There are several simple but useful site branding tags included. Commonly to be used in site footers and emails templates.

  • organization - Renders the name of the business, taken from Config var plugin.platformCore.organization.name
  • siteName - Renders the name of the site/product, taken from Config var plugin.platformCore.site.name
  • siteURL - Renders an absolute URL for the root of the site
  • siteLink - Renders an absolute link to the site, with the site name as the link text
  • year - Renders the current year, for use in copyright footers

7.2 Properties

New auto-namespaced equivalents of session, request and flash attributes are added to all controllers and taglibs exposed by plugins.

These properties are pluginRequestAttributes, pluginSession and pluginFlash.

They allow you to access these attributes from plugin code without having to worry about key name clashes with other plugins or the application:

class MyController {
	def beginPasswordReset = {
		pluginSession.resetMode = true
		pluginFlash.resetToken = resetTokenFactory.newTicket()
	}
}

7.3 Beans and utilities

There are a some UI utility classes and beans available:
  • grailsUiExtensions - Provides methods for setting and getting displayMessages
  • TagLibUtils - Provides helper functions for manipulating attributes, CSS class name lists etc.