Last updated by 5 years ago

Page: Ref Code Plugin, Version:1

Ref Code Plugin

This plugin provides an easy solution for 'code/description' reference/lookup data. Often in your business model you have simple reference/lookup tables with just code and description columns; e.g. Country (uk=United Kingdom, nl=Netherlands, ...), OrderStatus (C=Cancelled, N=New, P=Pending, S=Shipped), OrganizationType, ...

In Grails it's easy to create specific domain classes and generate the controller and views, but still you end up with code you have to maintain. An alternative in Grails is to use the inList constraint, but this type of constraint only uses really fixed values.

This plugin contains a simple single domain class in which you can store domains and the allowable values. The allowable values are split up in to the real value, a abbreviation, and a meaning. It also contains a taglib for easily creating HTML selects for a given domain, and a service which can be used to validate input values against the allowable values in custom constraints.

Installation

To install the Ref Code plugin type this command from your project's root folder:

grails install-plugin ref-code

The plugin does NOT provide a controller or views to maintain the ref codes. However you can generate them easily by running:

grails generate-all RefCode

RefCode TagLib

The ref code taglib provides the following tags:

select

Renders a HTML select for the given domain

Attributes:

domain - the domain name

Example:

<refcode:select domain="orderStatus" />
<refcode:select domain="orderStatus" noSelection="['':'']" />

abbreviation

Renders the abbreviation for the given domain and value

Attributes:

domain - the domain name value - the value

Example:

<refcode:abbreviation domain="orderStatus" value="1" />
<refcode:abbreviation domain="orderStatus" value="${order.status}"/>

meaning

Renders the meaningfor the given domain and value

Attributes:

domain - the domain name value - the value

Example:

<refcode:meaning domain="orderStatus" value="1" />
<refcode:meaning domain="orderStatus" value="${order.status}"/>

Domain Class validation

To validate input data against a domain's allowable values you can use the RefCodeService in your custom validator. Example:

class Order{

def refCodeService

.. <other properties> String status

static constraints = { status(validator: { val, obj -> return obj.refCodeService.validate("orderStatus", val) }) } }

Plugin version history

0.1 (May 4, 2008)