Annotations really provides a whole new view of programming things. Groovy also provides some of its own annotations one of them is Category. Lets take an example of using it. We create a IntegerUtil class and annotate it with Category. [java] @Category(Integer) class IntegerUtil { List<Integer> multiples(Integer...
Data Binding in grails is something that I love alot. In most of the cases we look at the Binding with respect to some domain class but binding can be one of the best candidate for searching and filtration. In my recent project we had a domain Class Article and the user could filter articles on different criteria. The page looks...
In our recent grails project, we were about to move to production so we decided to manage the database changes with liquibase. So we generated the changelog from development env by executing the command "grails generate-changelog /home/uday/projects/projectName/grails-app/migrations/changelog.xml" which contained all the table creation...
Testing was never so easy and intuitive before the use of Spock. Earlier when I was using grails unit testing, it never attracted me to write more and more test cases but with Spock you always keen to test each and every line of your code, testing the exceptions is one of them. You can always test the exceptions in grails unit test...
In my recent project we are using spock test cases to test our application and spock really made it easy for us to test those things we were not able to test in Grails Unit Test or testing such things dont look so intuitive in Grails Unit tests . One of the powerful method of spock testing is interaction based testing, which allow us to...
In one of my project we were reading the cookies so that we could do the processing accordingly. Now reading the cookie is easy but writing a unit test case for that action was little bit tricky for me because I wanted to test the behavior in case of when I find the cookie and when there is no desired cookie in the request. So the...
As we all know the default port for grails application is 8080, though we can change the port by running the application by following command [java] grails -Dserver.port=7070 run-app [/java] What if you want the application to run on 7070 by default. Grails provide a very easy way to that as well. You just need to write the...
I would explain this through a use case of my own project. A Program has many AdvertisingMaterial and we have subclasses of AdvertisingMaterial, FlashAd, ImageAd etc. The user wants the ability to filter the programs which had flashAds, imageAds etc. This required filtering on the basis of the class property that we have in...
We have a nice culture in our company where we sit together on every alternate Saturday and either share new things or we just learn about the technology we are using. This time we discussed about Groovy Meta Programming tricks and we watched the Meta Programming video of Jeff Brown. In that video the handling of Missing Method was really...
Working with groovy is really a cake walk. Whenever I get some free time I try to know more about it. Today I was just wondering on the net and I found some cool tips to execute groovy file in grails. There are so many other ways available to run groovy script in grails, I will share one of the way to do it. To know it we will take a...
Recently while working on my new Project I have the requirement where each domains need to have dateCreated and lastUpdated fields. So rather than adding these fields to each of the domain class we added them to template. Now whenever we create a domain class these two fields are added to it automatically. Next thing we want to add...
Again I am going to showcase few useful methods that GORM provides us to check whether the object is dirty or not (again from grails.org). First question could be what is a dirty object? An object is dirty if the current state of its properties does not match with its persistence values. It happens when you modify few properties of an...