Grails

Understanding Groovy 2.0 withLazyDefault and withEagerDefault methods

Sometimes there is need to get some default value in place of null values from a list, that was the reason I came across: withLazyDefault and withEagerDefault methods. My use case consisted of a list of user names with possibility of null elements, hence wherever the element was null, I wanted to return “unknown”. Although […]

Divya Setia
Divya Setia
Read

Grails

Implement Ajax call in Grails web-flow

In one of my recent project, i want to use grails web-flow with ajax call. It’s very easy to implement the web-flow with ajax call. Grails web-flow always track the actions on the basis of eventId & flow execution key. So, to implement ajax call in web-flow, we have to pass the event id & […]

Mohit Garg
Mohit Garg
Read

Grails

Two Interesting methods in Groovy 2.0 : takeWhile and dropWhile

Today I found two very interesting methods: takeWhile and dropWhile. The names itself reveals their work i.e. takeWhile (consider while some condition is true) and dropWhile (ignore while some condition is true). Although, these methods have been added to Groovy 1.8.7, but for character sequence, these methods are supported in Groovy 2.0 only. The takeWhile […]

Divya Setia
Divya Setia
Read

Grails

Groovy HTTP builder for sending multipart file.

I had two applications that communicate with each other through web-services. There I had a requirement to send multi-part file from one application to another. After searching I came out with the following solution and thought to share: [java] import org.apache.http.entity.mime.MultipartEntity import org.apache.http.entity.mime.HttpMultipartMode import org.apache.http.entity.mime.content.InputStreamBody import org.apache.http.entity.mime.content.StringBody import groovyx.net.http.* void sendMultiPartFile(CommonsMultipartFile multipartImageFile, String cityName) { […]

Divya Setia
Divya Setia
Read

Grails

Evaluating Expressions with groovy.util.Eval

A few days ago I faced a problem of evaluating dynamic expressions on domain objects. The scenario was that, depending upon the user input, I needed to sort a list of objects on some properties, which were nested deep in the object, e.g., [java] student.course?.college?.name // if a user chose to sort students by college […]

Imran Mir
Imran Mir
Read

Grails

What is Delegate ??

Suppose a scenario, where User and Account classes are linked as below: [groovy] class Account { String email String password // … other fields } class User { Account account String name String address // … other fields } [/groovy] At the time of creating a new User, and accessing the user members, we write […]

Amit Kumar
Amit Kumar
Read

Grails

Facebook ‘Like’ a wall post using Graph API

Hi, In one of my Grails project, i needed to ‘Like’ any Facebook wall post using facebook API. I searched about it and found a way to achieve this using Facebook Graph API and thought it worth sharing. To achieve it, we should have a valid facebook access_token, which can be obtained using steps described […]

Grails

Posting photos to Facebook album using Graph API

Hi, In my recent grails project, i needed to post images to the albums for Facebook Profile/ Fan page/ Group using facebook API. I searched a lot and find a way to achieve this using Facebook Graph API. To post any content over facebook, we need to have facebook access_token which can be obtained using […]

Grails

Dealing with immutable collections in Java

Perhaps, you know it before or just skipped it after going through Java API. But I really found it very helpful at this point.   Recently, I had a requirement in an open-source project, where users can iterate through the objects saved in collections (esp. List). But the problem was, we really didn’t want users […]

Salil
Salil
Read