Grails

Cool way to get/set processed HTML Markup in filters

Hi,   There was a case where i had to encrypt the HTML output of the GSP before displaying it to user. There are a lot of ways to do it, but i wanted to make is as simple as possible. Hence here is the pattern i used:   Note: This is just an example, […]

Kushal Likhi
Kushal Likhi
Read

Grails

Groovy: Overriding “Plus” operator in a class with interesting example

Have you ever wondered how to overload “plus” operator in Groovy ? It is as easy as adding toppings to your favourite pizza. Let me explain. Let us taka a class for Pizza:   [java] @ToString class Pizza { String name List<Topping> toppings double price } [/java] And another for the Topping: [java] @ToString class […]

Imran Mir
Imran Mir
Read

Grails

FindResults and FindResult Methods of Groovy

In almost all the applications that we work on, we have to transform elements of a collection in one way or the other. We can do it in different ways. Let there be a domain “Employee” with following attributes: [java] class Employee{ String firstName String lastName Double salary } [/java] And we have 5 Employees: […]

Vivek Sachdeva
Vivek Sachdeva
Read

Technology

Using Inject method in Groovy 2.0

A very useful enhanced method in Groovy 2.0 is inject method whose key purpose is to pass the outcome of first iteration to next iteration and keep on passing till all the elements of collections are processed. Lets start with an example, consider a class Employee with name and salary as attributes: [java] class Employee{ […]

Divya Setia
Divya Setia
Read

Technology

@Log annotation

@Log : This annotation provides the log object in groovy class. By using it you don’t need to create the Logger object, it automatically provides log object. Example: [groovy] import groovy.util.logging.Log @Log class Person { String name String address String city public void logDetails(){ log.info("Name:::${name}—>Address ::: ${address}—> city :::${city}") } } new Person(name:"Mohit Garg",address:"Address",city: "city").logDetails() […]

Mohit Garg
Mohit Garg
Read

Technology

TupleConstructor annotation in Groovy

@TupleConstructor annotation provides the classical constructor with default properties. It will create the constructor with first parameter as address, second parameter as name etc. Constructor implementation depends upon the order of the variable declaration. One thing you need to ensure that you need to pass the value in same order as used in variable declaration. […]

Mohit Garg
Mohit Garg
Read

Grails

Static Type Checking in Groovy 2.0

Groovy is a dynamic language. We can’t check any typo error, method or property missing error at compile time. To check typo error, method or  property missing at compile time, Groovy 2.0 introduces new features named as Static Type Checking which helps to check errors at compile time. To use static type checker in groovy […]

Mohit Garg
Mohit Garg
Read

Grails

How to implement AOP Profiling in Grails application

In one of my recent project, i want to profile method execution time. I have used Spring AOP to profile method execution time. It’s very easy to implement AOP profiling in grails 1. Suppose we have below mentioned service class, we want to log execution time of method saveDataStudent,saveDataUpdated methods in service class. We need […]

Mohit Garg
Mohit Garg
Read

Grails

Inject Methods/Properties to be available in all GSP Pages

Hi,   There could be cases where we would need to inject some methods or properties in all GSP pages.   As we know that the GSP pages extends GroovyPage class, hence injecting properties/methods in GroovyPage class can solve out purpose.   Example: Lets add appVersion property and a method to provide logo link irrespective […]

Kushal Likhi
Kushal Likhi
Read