I want to quickly share how you can sort a Map by its key/value/field of valueObject; in either ascending or descending order using Groovy I created a Map<String, Person> as follows: class Person { String name Date dateOfBirth static constraints = { } } Map people = [:] [*(11..20), *(1..10)].each { ...
Often I found it painful working on dates when I had to find a past/future date based on weeks, months or years. Groovy class org.codehaus.groovy.runtime.TimeCategory has very helpful & intutive syntax for working on dates. I am sure I need not to explain what each of the following statements will do: Date date = new Date() ...
public Map groupBy(Closure closure) Going through Groovy Collection, I found this powerful method which takes a Closure as parameter & based on the closure, it returns a map in which all unique values returned by closure act as keys. Lets take an example: If you want to group integers between 1 to 100 based on the integer...
While going through the grails-users mailing list, I found a question about restricting all URLs to end with '.html' & returning Error 404 for the default mappings. After spending some time, I was able to build a sample CRUD application restricting URLs to end with .html. I did the following steps for the same: 1. Create a new...
Grails has a lot of gems. One of my favorites (besides GORM) is GSP tags -- Grails makes it so easy to create new tags, now there is no reason to write java/groovy code inside GSPs. One of the features about GSP tags that I discovered and used today is that it is possible to invoke a GSP tag as a method call and assign the output of...
When we want to render a view using a template and the template makes use of a model object, the model object needs to be passed to the template using GSP tags. I am writing this because it took me a while to figure this out. Thanks to the wonderful contributors on the mailing list who helped me with this. To render the view to a...
Externalizing properties of an application has really come a long way, especially if you are using Grails. Just want to share as a quick tip how easy it is to externalize the properties in a Grails application. This is what all we have to do in-order to get something from a properties file. In config.groovy include the properties...
In this blog I want to share how can we customize home page while developing a Grails application. In grails, the default homepage is the web-app/index.gsp if we explicitly don`t specify any thing; but of-course that is not sufficient for all apps. We need to have a custom landing page instead of the default page provided by grails. ...
In grails web application development, use of frameworks has become essential . One of those frameworks which help us in making things simpler and life easy is jQuery. Why jQuery ? Fully Documented Great Community Tons of plugins Small size(14kb) Everything works in IE 6+,Firefox,Safari 2+,and Opera 9+ jQquery is a very...
BootStraping is something which is needed in most of the grails application. One of the frequently asked questions (and a valid requirement as well) is : How do you make Bootstraping happen only in a particular environment. This can be done by making use of one of the Grails utility class which allows you to inspect the environment in...