Grails

Writing JSON APIs : Part I – Creating a secure JSON API with Grails and Spring Security in 3 easy steps

We had a requirement in a recent project to expose some of the functionality we had via a JSON API. The functionality needed to be secure, as was the initial web interface which exposed the functionality. We were using Spring Security for the security aspect of our application. The spring security plugin, together with a […]

Vivek Krishna
Vivek Krishna
Read

Grails

Validating emails, urls and date using Java API

Using commons-validator jar for validation emails, date, url, credit card etc. This jar file is bundled with the grails jar files. So writing regular expressions or creating command objects/domains for the single field validation is overkilling. The jar file has a special class GenericValidator for validating well-known data types.

Bhagwat Kumar
Bhagwat Kumar
Read

Grails

Grails Spring Security Plugin: User Switcher

If you are using Grails Spring Security in your application, one killer functionality that we can easily provide is a simple user switcher Add this to your admin layout: [html] <sec:ifAllGranted roles=’ROLE_ADMIN’> <form action=’/j_spring_security_switch_user’ method=’POST’> Switch: <g:select from="${users}" optionKey="username" optionValue="displayInfo" name=’j_username’/> <input type=’submit’ value=’Switch’/> </form> </sec:ifAllGranted> <sec:ifSwitched> <a href=’${request.contextPath}/j_spring_security_exit_user’> Resume as <sec:switchedUserOriginalUsername/> </a> </sec:ifSwitched> [/html] In […]

Himanshu Seth
Himanshu Seth
Read

Grails

Grails: Find number of queries executed for a particular request

When response time of a page is slow, we might be interested in viewing database queries executed on that page. Enabling SQL Logging shows all queries but we are interested in queries for that particular request only. We can get this information by just simply adding the following filter to our application(Filters in Grails) [groovy] […]

Himanshu Seth
Himanshu Seth
Read

Grails

Criteria Query with Left Outer Join

In Grails app development, when using criteria queries, we often find cases for Outer joins. Lets take an example. We have two domain classes with us: [java] class Blog { String title String content static hasMany = [comments: Comment] static constraints = { } } [/java] and [java] class Comment { String text static belongsTo […]

Himanshu Seth
Himanshu Seth
Read

Grails

Grails bindData to collections

Recently, I was stuck with a scenario where I was trying to bind a list of objects in my controller. While trying the way as suggested in the grails docs I was getting some weird IndexOutOfBoundException. Luckily I found a good solution on the grails mailing list: http://grails.1312388.n4.nabble.com/Databinding-Collection-of-non-domain-objects-tp3260578p3260856.html Thanks to mkwhit for asking this and […]

Mohd Farid
Mohd Farid
Read

Grails

Creating a Perfect System in few minutes.

There might come up a case where you need to install same kind of OS and other Softwares( which are required for daily use) on multiple systems. One of the ways to do it is follow the same procedure on each of the machines, which is obviously a pain. Here’s a easy way to do […]

Hitesh Bhatia
Hitesh Bhatia
Read

Grails

Create Image of System in USB, Using Clonezilla

Clonezilla is a software that can be used to make image of system that can later be used to install this image on new system, to make it a clone of former system. Here are the steps to create image of a system by clonezilla Create a Bootable USB drive Using Clonezilla. Follow the link […]

Hitesh Bhatia
Hitesh Bhatia
Read

Grails

Log Sql in grails for a piece of code

There are time when we need to see the sql logging statement just for a method of for a particular code. Although we already have logSql property in DataSource to do it for us but it sometimes makes difficult if we need to see the log for a small piece of code rather than for […]

Services