Thursday, January 14, 2010

Grails Multiple Select Tag

Though it would seem like a feature available right out of the box, having a tag that allows a user to select multiple options in a select box is in fact, a custom tag.

The src code for the tag can be found here. just copy the src into a file named MultiselectTagLib.groovy in the taglib dir.

Directions for use, can be found here

As an example, suppose we had a Statement class which contains multiple payments

class Statement {
String name
Date stmtDate

static hasMany = [payments:Payment]

static constraints = {

class Payment {
Double amt
Date txnDate

static constraints = {

then the gsp tag to select payments for a statement would look like

<g:select optionKey="id" optionValue="amt" from="${Payment.list()}" name="payments"
value="${statementInstance.payments}" multiple="multiple" />

No comments:

Post a Comment