Grails Cookbook - A collection of tutorials and examples

Grails currencySelect Tag Example

The Grails currencySelect tag (<g:currencySelect>) can be used to generate a dropdown list of currencies. This will show a simple example on how to use this.

Example

Let's begin by showing the sample output of the sample code:
pz2

The domain class used in the example is this:

package asia.grails.demo
class Product {
    String name
    String priceCurrency
    BigDecimal price
    static constraints = {
    }
}

The code to render the dropdown box is this:
<g:currencySelect name="priceCurrency" value="${productInstance?.priceCurrency}"/>

And the generated HTML code is this:

<select name="priceCurrency" id="priceCurrency" >
<option value="EUR" >EUR</option>
<option value="XCD" >XCD</option>
<option value="USD" >USD</option>
<option value="XOF" >XOF</option>
<option value="NOK" >NOK</option>
<option value="AUD" >AUD</option>
<option value="XAF" >XAF</option>
<option value="NZD" >NZD</option>
<option value="MAD" >MAD</option>
<option value="DKK" >DKK</option>
<option value="GBP" >GBP</option>
<option value="CHF" >CHF</option>
<option value="XPF" >XPF</option>
<option value="ILS" >ILS</option>
<option value="ROL" >ROL</option>
<option value="TRL" >TRL</option>
</select>

As you could see, the list only have limited selection. The value and description are also the same.

Other Grails Tag Examples


Tags: currencySelect, Grails Tag