Grails

Open Pdf in Google Docs using Time Based Cache in Grails

Recently, we had a requirement where secure URLs were to be made accessible to Google. Our implementation was to send a url with token valid for 10 seconds. The token expired automatically after 10 seconds. We used time based cache for this as described here: T set max time to 10 seconds , I set default MaxAge to 10 millis in above...

by Hitesh Bhatia
Tag: Groovy
23-Jun-2010

Grails

Password validation with certain conditions

Hi Friends, I needed to validate password for certain conditions. As per the requirements, any valid must password must pass the following conditions: Minimum of 7 characters Must have numbers and letters Must have at least a one special characters- "!,@,#,$,%,&,*,(,),+" I wrote the following method to meet the...

by Amit Jain
Tag: Groovy
14-Jun-2010

Grails, Technology

Working With Soap Calls

Hey, SOAP is one of the popular ways of working with web-services another being REST (another of my blog)), while working with any of the SOAP based API, you will get a WSDL (web services description/definition language) describing what all methods are supported by the web service. Its a rather complicated XML document. A few days...

by Sachin
Tag: Groovy
08-Jun-2010

Grails

Grails : Difference b/w two dates with fine-grained details

Hi Friends, To retrieve difference between two dates with finer details which would display their difference as 2 years 7 weeks 3 days 2 hours 5 mins ago is given below. /** * Returns differnce b/w new Date and old date as Map holding difference in years, weeks, days, hrs, mins & secs */ public static Map...

by Amit Jain
Tag: Groovy
14-May-2010

Grails

Create JSON object Using Grails converter (Only selective fields from lists of objects)

This post might help you if you want to get JSON (JavaScript Object Notation) Object on browser. Grails framework provides you very efficient way to achieve this. For this you need to import grails JSON convertor in your code. import grails.converters.JSON Below is the code snapshot which converts java based lists of Objects to...

by Salil
Tag: Groovy
13-May-2010

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: Groovy
03-May-2010

Technology

Converting pdf file to image file using imagemagick and groovy

Recently in one of my project user have the requirement where he can upload the pdf file and its get converted into the image file, that can be used by the user for manipulations. After looking at here and there finally we find out the imagemagick tool which converts pdf file to image file. Its very easy to use this tool, all you need...

by Uday Pratap Singh
Tag: Groovy
19-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: Groovy
15-Apr-2010

Technology

XmlSlurper made it simple

Hi! We had a myForm.html file (accessible only from the third party) where in we needed to update the form containing input/select/check boxes with the values we had in the request params and then render it. So we used xmlslurper for the same. Without much effort, it just worked great. Following is the code we wrote: import...

by Amit Jain
Tag: Groovy
26-Mar-2010

Grails

Groovy: Create class with dynamic properties

I recently came across a way in Groovy to define a class which can have dynamic getters and setters and properties can be added on the fly. The following code creates a class "MyExpandableClass" and defines two methods in the "getProperty and setProperty". If we define these two methods in a groovy class, then calls to any getter or...

by Himanshu Seth
Tag: Groovy
25-Nov-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: Groovy
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: Groovy
22-Apr-2009