Grails Cookbook - A collection of tutorials and examples

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.

Grails datePicker Tag

The datePicker tag (<g:datePicker>) can be used to render an HTML for date input. It may render the input components for the day, month, year, hour and second. What is rendered can be controlled depending on parameter used. here are some examples:

Groovy Switch Statement Examples

The Switch statement in Groovy is more powerful than in Java. There are things that are easy to do in Groovy switch statements that are not available in Java. It is also more concise and easier to read. Below are several examples on how to use Groovy switch statements.

Groovy List Tutorial And Examples

A list is a common data structure that is used to store a collection of data. This can be used to store varying amount of data where the number of items is only determined at run time. Or it can also be used to store large amount of data where having different variables for each is not practical. Below are examples on how to use and manipulate List in Groovy.

Groovy Substring Examples

Getting a substring from another String is one of the basic building blocks of String manipulation. Most programming languages supports it out of the box. In Groovy, there are some cool ways of how to perform this operation. Below are some examples on different ways of getting substrings in Groovy.

Groovy Add To Map Examples

Maps are very useful in programming. It can be used to cache results of expensive operations to help improve performance. One of the basic operation in maps is how to add entries to it. Below are some examples on how to Add or put values to a map in Groovy.

Groovy Array Length

Array manipulation is common in any programming language. Here is a sample code on how to get the the length of an array in Groovy.

Groovy Copy File Examples

When writing batch programs, it is common to write code to copy files from one directory to another. Here are examples on how to Copy Files in Groovy.

Grails createLinkTo Tag Example

The Grails createLinkTo Tag renders the path or url to a static resource. For example: css, images, and javascript files. This does not render an anchor tag or image tag to the resource, but just the URL that can be used inside others tags, JavaScript, etc. Here are some examples