Grails Cookbook - A collection of tutorials and examples

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

Grails createLink Tag Example

The Grails createLink Tag renders the necessary path or url to a resource depending on the given parameters. This does not render an anchor tag, but just the URL that can be used inside an anchor tag, JavaScript, etc. Here are some examples

Groovy FindAll

Groovy is popular for writing short and concise codes. Programs that contains many lines of code using Java can be shortened in Groovy. This greatly helps in developer productivity. A feature that is commonly used in Groovy is in searching for items in a collection. The Groovy FindAll method searches for a subset of a collection that matches a given criteria. Here are some examples on how to use Groovy FindAll:

Groovy Find

Groovy is one of the coolest language available because it makes coding so much easier. Long Java codes can be written in Groovy in fewer lines that are much more readable. One of the most used feature in Groovy is in searching. The Groovy Find method can be used to search for a single object in a collection, given a condition on what needs to be searched for. Below are some examples on how to use Groovy Find for searching.

Groovy Def Declaration Examples

When we declare a variable or function in Groovy, we can use the def keyword to define the type. The Groovy Def can be used if we don't want to restrict the type of an object. Hence, we can change what can be assigned to a variable any time during runtime. When we use Groovy def to declare something, it is similar to declaring it as an Object class. Because the class Object is the root class of all classes, you can assign anything to a variable of type Object. Here are some examples on how to use def in Groovy.

Groovy File Examples

File processing is one of the most common task in programming. Fortunately, Groovy makes file manipulation easier. Things that are long and complicated in Java are now very much concise in Groovy. Here are some Groovy File programming examples.

Grails Render Examples

When coding controllers, we can use the render method to return contents to the browser. Listed below are examples on different ways of using Grails render inside controllers.

Grails Redirect Examples

Grails redirect is a very useful controller method when writing web applications. To redirect flow from one action to the next. Here are some examples on how to use Grails redirect.

Grails Redirect vs Forward

Both redirect and forward methods in controller code will send you to another controller action. This will show the difference between Grails Redirect and Forward.