Grails

Grails: Few tips for writing integration tests

Just thought I would share with you few tips or key points we should remember while writing integration test cases: 1.  Flush and clear the session object for every single test case for example class FooTests extends GroovyTestCase { def sessionFactory void setUp() { sessionFactory.currentSession.flush() ...

by Amit Jain
Tag: Grails
05-Nov-2009

Grails

Batch Processing In Grails

In one of my project assignments I needed to insert large number of records into the database. I had to read the objects from an external source. Once I read all of the objects into a List, I iterated the list to save each one of them individually. In the beginning the process carried on fine but as the time passed the execution slowed...

by Imran Mir
Tag: Grails
09-Sep-2009

Grails

Grails: reverse url mapping to generate urls ending with “.html”

Hi Friends, Recently I came across a problem, where the url of the links were to be generated dynamically based on the controller and action to be executed and  should end with ".html". Reverse url mappings came to my rescue, which can be implemented using <g:link> GSP tag. Then I tried this, In UrlMappings.groovy file : ...

by Amit Jain
Tag: Grails
28-Aug-2009

Grails

WordPress plugin : workaround to get excerpt of recent posts & only published messages

While integrating the blogs using wordpress plugin in one of the project I am working on. I observed that using current version(0.1) of wordpress plugin, when we request for recent posts, it returns not only published blogs but also blogs with status as draft(which are not yet published). Along with that, we needed to show excerpt of...

by Amit Jain
Tag: Grails
07-Aug-2009

Grails

Accessing Session Map in the Domain or Service Layer

The Session Map is available in Grails in the Views, TagLibs and the Controllers. That is, it can be directly accessed by the name "session". If the Session Map is required to be accessed in the Service Layer or the Domain layer, such a straightforward approach will not work. In this case, a class which is a part of the Spring Framework...

by Vivek Krishna
Tag: Grails
16-Jul-2009

Grails

Grails : Mutliple Paginations Using g:paginate tag

In my project, we needed a support for multiple paginations on the same page. For the same, we maintained the state of offset of different pagination tags and let tag use its specific offset rather than the general i.e from param.offset. Assuming, we need two paginations on the same page. Lets assume the scenario where we have a...

by Amit Jain
Tag: Grails
23-Apr-2009

Grails

Grails Functional Testing: Uploading a file using G-Func plugin

At Intelligrape we face many challenges while developing web-applications. One of the small challenge was to test the web pages that contains file input field <input type="File">(to upload files). After few hours drilling with Canoo webtest plugin I decided to use the new fabulous plugin, Grails functional Testing by Marc Palmer...

by Chandan Luthra
Tag: Grails
22-Apr-2009

Grails

Grails : Upload and Render File

Lets discuss how can we upload a file and store it in a database, along with that how do we render it on the gsp page. I am taking an example to upload and render the image in this blog, though the code would be same for any other file. So Lets consider I have a domain class with the name Person class Person { . ...

by Amit Jain
Tag: Grails
16-Apr-2009

Grails

Groovy Finding Past/Future Dates

Often I found it painful working on dates when I had to find a past/future date based on weeks, months or years. Groovy class org.codehaus.groovy.runtime.TimeCategory has very helpful & intutive syntax for working on dates. I am sure I need not to explain what each of the following statements will do: Date date = new Date() ...

by Aman Aggarwal
Tag: Grails
06-Apr-2009

Grails

Groovy Collection method: groupBy()

public Map groupBy(Closure closure) Going through Groovy Collection, I found this powerful method which takes a Closure as parameter & based on the closure, it returns a map in which all unique values returned by closure act as keys. Lets take an example: If you want to group integers between 1 to 100 based on the integer...

by Aman Aggarwal
Tag: Grails
06-Apr-2009

Grails

Restricting all URLs to end with .html in a Grails Application

While going through the grails-users mailing list, I found a question about restricting all URLs to end with '.html' & returning Error 404 for the default mappings. After spending some time, I was able to build a sample CRUD application restricting URLs to end with .html. I did the following steps for the same: 1. Create a new...

by Aman Aggarwal
Tag: Grails
03-Apr-2009

Grails

How to use $.getJSON() method of jQuery with grails?

How to use $.getJSON() method of jQuery with grails? Retriving a JSON string from Grails is very easy. You have to just write the following in your controller's action Let me explain you with an example of populating a HTML table using JSON response: In this example, we have table with columns - name,address and gender. We want the...

by Chandan Luthra
Tag: Grails
02-Mar-2009