{"id":136,"date":"2009-07-16T19:23:30","date_gmt":"2009-07-16T13:53:30","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=136"},"modified":"2009-07-17T11:49:19","modified_gmt":"2009-07-17T06:19:19","slug":"accessing-session-map-in-the-domain-or-service-layer","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/accessing-session-map-in-the-domain-or-service-layer\/","title":{"rendered":"Accessing Session Map in the Domain or Service Layer"},"content":{"rendered":"<p>The Session Map is available in Grails in the Views, TagLibs and the Controllers. That is, it can be directly accessed by the name &#8220;session&#8221;. 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 can be used which gives the current context, the request attributes and the session.  This class along with HttpSession have to be imported by issuing the following statements.<\/p>\n<blockquote>\n<pre lang=\"groovy\">import org.springframework.web.context.request.RequestContextHolder<\/pre>\n<\/blockquote>\n<p>Now, the session variable can be defined in the Service class or Domain method as:<\/p>\n<blockquote>\n<pre lang=\"groovy\">def session = RequestContextHolder.currentRequestAttributes().getSession()<\/pre>\n<\/blockquote>\n<p>The session attributes can now be accessed as<\/p>\n<blockquote>\n<pre lang=\"groovy\">session.attribute<\/pre>\n<\/blockquote>\n<p>Hope this helps.<\/p>\n<p>S Vivek Krishna<\/p>\n<p>vivek@IntelliGrape.com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Session Map is available in Grails in the Views, TagLibs and the Controllers. That is, it can be directly accessed by the name &#8220;session&#8221;. 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 [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":14},"categories":[7],"tags":[4840,108,4841],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/136"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=136"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/136\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}