Grails Cookbook - A collection of tutorials and examples

Grails formatNumber Tag Example

The Grails' <g:formatNumber> tag can be used inside GSPs to control the format when displaying numerical values. This is based onJava's DecimalFormat or the JSTL formatNumber tag. Below are some examples on how to use this tag.

Groovy Sort Information in XML Document

Given an XML, we can modify it's contents by sorting the entries based on some criteria. Below is a simple code example on how to do that.

Groovy Edit/Modify XML Examples

Sometimes, it is not enough to parse or create XML documents. There are times when we need to edit an XML information for further processing. Below are examples on how to modify or edit existing XML document.

Groovy Create XML Document Examples

In previous examples, we show how to parse XML documents using XmlSlurper and XmlParser. This post will show the opposite. We give examples on how to create XML documents.

Groovy XmlParser Examples for Parsing XML

Parsing XML information is common to many projects. We showed int he previous post on how to parse XML documents using XmlSlurper. This post will focus on giving examples on how to parse documents using XmlParser.

Groovy XmlSlurper Examples for Parsing XML

One common task in an enterprise application is parsing of XML documents. This task is commonly complicated in Java with lots of plumbing code, but is fairly easy and straightforward in Groovy. Below are examples on how to parse XML in Groovy using XmlSlurper. Visit this post if you wish to parse XML using XmlParser.

Grails formatBoolean Tag Example

The Grails' <g:formatBoolean> tag can be used to format boolean values for rendering inside GSP view page. Here are some examples on how to use this tag.

Grails formatDate Tag Example

The Grails' <g:formatDate> tag can be used inside GSPs to format java.util.Date instances for display. The tag is based on Java's SimpleDateFormat class. Below are some examples on how to use this tag.

Grails elseif Tag Example

The Grails elseif tag (<g:elseif>) tag is used together with the if tag (<g:if>) and optionally with the else tag (<g:else>). The elseif is used if there are more than one test that needs to be performed. Here is a simple example on how to use this tag.

Grails else Tag Example

The Grails else tag (<g:else>) tag is used together with the if tag (<g:if>). The else portion is rendered when the if part failed. This is used to have conditional statements inside a GSP. This is useful if we want to display a certain view code or another depending on some condition. here is a simple example on how to use the Grails else tag.