Vishal Sahu

Software developer by profession , passionate about Groovy, Grails and Java/J2EE technologies and a great lover of Open Source.

Grails

Install Apps on Facebook Fan page using API

Hi, In my current grails project, we are using Facebooks Apps for our application so that any user who wish to use that app, can attach it with his/her Facebook Fan Page manually by visiting the App Profile Page and then adding it to the Fan Page. Then the attached facebook app can fetch data from our project. But few days ago,...

18-Dec-2011

Grails

Integrating Google plus in grails application

In my current project, i needed to integrate Google+ in the application using server-side API. Google uses OAuth2.0 protocol for authorization when our application tries to access the data. All we require is an access token to fetch data from Google using REST calls which serves data in JSON format. I implemented it using Web Server...

06-Dec-2011

Grails

Setting System property from command line in grails

Hi, In one of my recent grails project, i needed to set System property from command line while running the grails application. I looked for it and found a simple solution to do so and found it worth sharing. Suppose we want to set any property, say app.property="propertyValue", then the command to set the property in grails...

24-Aug-2011

Grails

Generating EAN-8 standard barcode using Barcode4J

Hi, In one of my project i needed to generate EAN-8 standard bar-code for identifying the various products. I searched for various libraries available for generating bar-code and found a library to do so. The library i used for generating the bar-code is Barcode4J. You can download it from here Barcode4J is a flexible generator...

14-Apr-2011

Grails

Paypal Integration : Auto redirecting to application after processing payment

Hi, In my recent grails project, i needed to return back to the application after processing payment at the paypal website. I searched a lot about it. Then i found the solution to do so and thought it worth sharing. Here are the steps i followed:- 1. The Paypal button:- This is the code for putting the paypal button in any...

15-Mar-2011

Grails

Converting date from one timezone to another in groovy

Hi, In my recent grails project, i came across the situation where i needed to convert the date in given timezone to the date in another timezone. I searched a lot about it and got many solutions for this problem and then i came out with a simple way to do so. Lets i have a date in TimeZone say oldTimeZone and i want to convert it to...

09-Feb-2011

Grails

JQuery script to put focus on first field of any page

Hi, In my recent grails project, i needed to put focus on the first field of any page whenever the page loads. The requirement is such that if the page contains errors then the focus should be on the first input field which has errors. I searched a lot and with the help of my colleague we came out with a simple JQuery script to put...

13-Jan-2011

Grails

Recursively searching for similar files on file-system in groovy

Hi, In my recent grails project, i needed to find the existence of particular files on file system. I needed to search in a directory and all of its subdirectories and look into them if the files with the given format exists in it or not. If the files exists, then it should return the complete path of the file. I searched a lot and...

13-Dec-2010

Grails

Testing custom validator in grails unit test case

Hi, In my recent grails project, i needed to write unit test cases for testing custom validators which i created in command objects. To test validators, there is a method provided by grails "mockForConstraintsTests()" for validating constraints on Domain as well as Command-Object fields. Let us take a scenario where we needed to use...

14-Nov-2010

Grails

Regex to match exact word in a string

Hi, In my recent grails project, i needed to check the occurrence of a word in a string. I could have used contains() method of groovy , but the problem with contains() is that it also matches the word if the word is contained as a substring in any word. I searched a lot, but nothing worked out so i decided to use Regular expression...

14-Oct-2010

Grails

Grails pagination on a ArrayList

Hi all, In my recent grails project, i needed to paginate on an array list, so I wrote a function and thought would share it with you all. public List getFilteredList(int max, int offset) { max = Math.min(max ?: 25, 100) offset = (offset && offset>0) ?: 0 List names = getNames() //Loads the complete list ...

14-Sep-2010

Grails

Creating select tag with optgroup in Grails

Hi, In one of my projects i needed to create a select-input tag with OPTGROUP options. I searched a lot about it and found that g:select tag do not support OPTGROUP So to solve this problem, i created a simple optgroup tag using Html and grails taglib. I created a Map for the values to be used in the select tag and pass it...

10-Aug-2010