In my current grails application, we have started using the AngularJS after realizing that the GSP template engine is a bit slow. Now, I realize how efficient AngularJS can be, and think of sharing my first impressions while using AngularJS with grails app. Following are some of the reasons, that I find, makes AngularJS stands out: ...
The other day I was reading the Grails docs and I came across a useful GSP tag: grep. I have been using Grails for over 3 years now but just recently got to see this new tag which has eased my life a bit in situations where the list of objects have to be filtered and iterated at the same time to perform some operations on them. The GSP...
JQuery mobile provides set of features which are supported on almost all smartphones such as touch UI, ajax navigation, animated page transitions. Building jQuery mobile page is very simple, here's how: A jQuery Mobile site must start with an HTML5 'doctype' to take full advantage of all of the framework's features. First of all you...
Here we are going to talk about a scenario where there are some records in database which are specific to locale and they need to be displayed as per user's current locale at number of places.Also user can change its preferred locale. For this I preferred to set the user's locale in the session object. There are two ways to do this :- ...
Recently, I used Taglib to centralize the effect of URL mapping related changes of my grails application. [java] def userPageLink = {attrs, body -> def user = User.read(attrs.id) out << g.link(controller: 'user', action: 'show', params: [name: user.name]) {body()} } [/java] So wherever I need a link to user page, I...
We use internationalization feature in grails using message tag in GSP pages. However arbitrary Groovy/Grails (e.g. tags) code can not be used in JavaScript as they are not executed on server side. To overcome this I used the following way : Declare a JSON object in js file or any where else so that this object is global one. Create a...
We have a setup where a backend thread, fired by the Spring Events, does some processing, generates a PDF and emails the result to the user. The code we were using to generate the HTML from a GSP to be converted to a PDF using iText was as follows : [java] def webRequest = RequestContextHolder.getRequestAttributes() ...
Today while working on a project, I paired up with my colleague (Uday) and we found that we can render a gsp template in a different manner also. Grails provide us a "tmpl" namespace for rendering the GSP templates. The old way that we use to render a gsp template The other way for rendering the template. Like me,...
There are situations where you might want to know the Locale of the user as set in the session in your GSP so that you can show text in a particular language/manner. Here the Spring framework's SessionLocaleResolver can come to the rescue. In one of our recent Grails projects, we did the following in one of our GSPs to display the content...
Restricting the length of a string on gsps is a common scenario in most of our projects. Groovy's metaprogramming magic made it too simple for me. I added the following lines of code to Bootstrap.groovy: Object.metaClass.trimLength = {Integer stringLength -> String trimString = delegate?.toString() String...
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...