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...
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...
(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...
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...
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...
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...
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...
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...
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...
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~~ ...
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...
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:...