Grails

Change user preferred locale using spring’s SessionLocaleResolver

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 :- ...

by Nitesh
Tag: Spring
11-May-2012

Grails

Request Mocking to use groovyPagesTemplateEngine in backend threads

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() ...

by Vivek Krishna
Tag: Spring
27-Dec-2010

Grails

Finding User’s Session Locale in GSP

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...

by Abhishek Tejpaul
Tag: Spring
14-Jul-2010

Grails

Overriding default Transactional Behaviour in Grails Services using Annotations

In a project, we needed to have fine tune the transaction behaviour on our Service classes. One service method was calling the a method in another service. The calling service method A was to happen in one transaction and the called service method B in its own transaction. This was required because we needed to persist the error log from...

by Vivek Krishna
Tag: Spring
28-Apr-2010

Grails

Injecting Spring Beans with data from Config

In one of the projects, we had to externalize the Config file to be in a properties file. All configurations related to the application were to be stored in that file. We had a few spring beans, like the JMS connection factory, which needs the brokerURL which should ideally be an external configuration as it is will be environment...

by Vivek Krishna
Tag: Spring
15-Apr-2010

Grails

Accessing Session Map in the Domain or Service Layer

The Session Map is available in Grails in the Views, TagLibs and the Controllers. That is, it can be directly accessed by the name "session". If the Session Map is required to be accessed in the Service Layer or the Domain layer, such a straightforward approach will not work. In this case, a class which is a part of the Spring Framework...

by Vivek Krishna
Tag: Spring
16-Jul-2009