Grails

Injecting Method to trim string length on gsp pages

Restricting the length of a string on gsps is a common scenario in most of our projects. Groovy's metaprogramming magic made it too simple for me. I added the following lines of code to Bootstrap.groovy: Object.metaClass.trimLength = {Integer stringLength -> String trimString = delegate?.toString() String...

by Aman Aggarwal
Tag: Grails
03-May-2010

Grails

Overriding default Transactional Behaviour in Grails Services using Annotations

In a project, we needed to have fine tune the transaction behaviour on our Service classes. One service method was calling the a method in another service. The calling service method A was to happen in one transaction and the called service method B in its own transaction. This was required because we needed to persist the error log from...

by Vivek Krishna
Tag: Grails
28-Apr-2010

Grails

Test Link

(based on Tomás Lin’s truthlink) This is useful when one requires link on certain condition. Instead of first using condition tag and then tag for link these can be combined into one using taglib. text or Text Other way of doing this is by using taglib. class...

by Hitesh Bhatia
Tag: Grails
19-Apr-2010

Grails

Setting the timeout interval of a HttpSession

In my project, there was a requirement to set the session time out interval and i had no idea about how to implement it. Then my colleague Himanshu Seth came to rescue. This guy has already done it. All you have to do is to set the maximum time out interval in the session. Here is the sample code. declare a SESSION_TIMEOUT constant in...

by gaurav
Tag: Grails
15-Apr-2010

Grails

Injecting Spring Beans with data from Config

In one of the projects, we had to externalize the Config file to be in a properties file. All configurations related to the application were to be stored in that file. We had a few spring beans, like the JMS connection factory, which needs the brokerURL which should ideally be an external configuration as it is will be environment...

by Vivek Krishna
Tag: Grails
15-Apr-2010

Grails

Creating image thumbnails through Grails ImageTools plugin

In one of the projects recently, we had to generate the thumbnails dynamically from the client-provided images. We decided to use the Grails plugin named: ImageTools. This is a very basic plugin but provided very quick and stable solution to our use-case. You can read more about the plugin and how to install it here . We decided to...

by Abhishek Tejpaul
Tag: Grails
23-Mar-2010

Grails

Grails JMS Plugin and Redelivery Policy

On a project, we needed to configure the redelivery mechanism for the JMS queue. That is, a poisonous message was to be sent to a Dead Letter Queue if a set number of attempts failed, so that the other messages in the queue could be processed. The JMS Plugin version used was 0.5 Merely configuring ActiveMQ for setting up a Dead Letter...

by Vivek Krishna
Tag: Grails
18-Mar-2010

Grails

Grails: handling StaleObjectStateException and making executeUpdate transactional

Recently I encountered a StaleObjectStateException which said "Row was updated or deleted by another transaction." We were just updating multiple objects of the same domain inside a loop. So we used executeUpdate statement instead of myClass.save() method to update the records, which worked. ReserveAccount.executeUpdate("update...

by Amit Jain
Tag: Grails
06-Mar-2010

Grails

My experience of using jasper reports with grails application

In my project we needed to generate certain pdf reports. Then while exploring the options available, I encountered a PDF plugin, which renders gsp page and returns the PDF report. It looked good for the simple reports but may not be a good idea if the report are complex. Then with the help of one of my collegue, we decided to rather...

by Amit Jain
Tag: Grails
25-Feb-2010

Grails

Grails Integration Tests : Access your application path

Hi Friends, Recently I needed to access my grails application's path while writing an integration test. I tried to do it with servlet context, Application Holder and few more options. But none worked. Then I encountered the simplest way as given below, which worked. System.properties['base.dir'] Cheers! ~~Amit Jain~~ ...

by Amit Jain
Tag: Grails
21-Jan-2010

Grails

Login user for Integration test when using Jsecurity plugin

Hello Friends, I was using Jsecurity plugin in my project. There was an action in a controller which needed logged in user information and I was finding it difficult to write an integration test for the same. Then Brent Fisher shared the following code which worked nicely for both services and controllers: import...

by Amit Jain
Tag: Grails
07-Dec-2009

Grails

Rescheduling a Quartz job programatically

In our current project on Grails we faced a problem  where we need to change the schedule of quartz job programmatically. The timeout value is read from the database. After doing some googling and digging mailing lists we found the following way- class MyJob{ static triggers = { simple name: 'mySimpleTrigger', group:...

by Bhagwat Kumar
Tag: Grails
01-Dec-2009