Skip to end of metadata
Go to start of metadata
This is work in progress

Some Groovy basics

And that compiles? But some common class doesn't have that method?

Groovy adds utility methods to a lot of common classes. You'll find the details referred to as the GDK - and its available on http://groovy.codehaus.org/groovy-jdk/

An example:

This gives the content of the web page http://www.vg.no. Resolution is as follows.

The string is a groovy.lang.GString. This class does not have a toURL() method.

However, it has got an invokeMethod. This method does a toString, and then tries to call the method (in this case , toURL()) on the object returned from toString.

toString returns a java.lang.String. This class does not have a toURL() method. However, there are methods added by grooovy to make stuff better. These methods can be found on the GDK link above. For java.lang.String, a getURL is added which returns a java.net.URL. getText is then called on this object.

Getting started with Grails

Useful links

How do I create an application I can toy around with?

Do the following:

See below for how to use Maven for building your Grails project.

Removing the ~/.grails directory can sometimes solve strange errors

Try it if you don't understand why you get a strange error.

How do you upgrade a Grails project to a new version of the Grails framework?

  1. download the new grails version
  2. upgrade your grails project like this:

Using Maven with Grails

How do I use Maven with Grails?

Use the Maven plugin for Grails.

Create a Maven pom for your project like this:

Note: You might need to add a log4j dependency in your pom.xml to get your project to compile.

How do I use mysql with a maven-based grails project?

Add the mysql dependency to the POM:

Then, update grails-app/conf/DataSource.groovy:

There is an underlying assumption here: All developers and test instances will run mysql without a root password. This might not be a good idea if tests use live data.

It is also not a good idea to let the application update the schema in production use, so switch that off.

Next, start mysql and create your database

I have not set the locale or character set for the database here. You should.

Next, package and run the application:

Domain classes

Which standard methods should you implement in a domain class?

It is a good idea to implement String toString() for instance like this:

This is particularly important if you are using scaffolding - otherwise the views for the scaffolded pages will use "ID: Type" in relationships (drop-down selects and cross-reference links).

How do you group domain classes in packages?

todo

How do you handle non-persistent domain classes in Grails?

todo

Services

What are grails services used for?

They are basically used for the same things that a spring service bean, or an EJB session bean are used for, i.e. providing re-usable services for the front-end part of an application, handling transactions, and handling integration with external services. The following illustration gives one example of how they can be used in a Grails + Java context!grails_and_spring2.png!
(Figure from http://www.grails-exchange.com/files/DaveSyer%20-%20Grails&Spring.pdf)

How do you create a service?

Use the grails create-service method.

Labels:
grails grails Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.