@@ -20,6 +20,7 @@ import javax.servlet.http.HttpServletRequest
2020import javax.servlet.http.HttpServletResponse
2121import javax.servlet.http.HttpSession
2222import org.springframework.web.util.WebUtils
23+ import javax.servlet.ServletContext
2324
2425/**
2526* <p >This plug-in adds methods to the Servlet API interfaces to make them more Grailsy. For example all classes that implement
@@ -54,17 +55,27 @@ class ServletsGrailsPlugin {
5455 delegate. setAttribute(name, value)
5556 }
5657 }
58+
59+ def getAttributeSubscript = { String key ->
60+ delegate. getAttribute(key)
61+ }
62+ def setAttributeSubScript = { String key , Object val ->
63+ delegate. setAttribute(key, val)
64+ }
65+
66+ // enables acces to servlet context with servletContext.foo syntax
67+ ServletContext . metaClass. getProperty = getAttributeClosure
68+ ServletContext . metaClass. setProperty = setAttributeClosure
69+ ServletContext . metaClass. getAt = getAttributeSubscript
70+ ServletContext . metaClass. putAt = setAttributeSubScript
71+
5772 // enables access to session attributes using session.foo syntax
5873 HttpSession . metaClass. getProperty = getAttributeClosure
5974 HttpSession . metaClass. setProperty = setAttributeClosure
6075 // enables access to session attributes with session["foo"] syntax
61- HttpSession . metaClass. getAt = { String key ->
62- delegate. getAttribute(key)
63- }
76+ HttpSession . metaClass. getAt = getAttributeSubscript
6477 // enables setting of session attributes with session["foo"] = "bar" syntax
65- HttpSession . metaClass. putAt = { String key , Object val ->
66- delegate. setAttribute(key, val)
67- }
78+ HttpSession . metaClass. putAt = setAttributeSubScript
6879
6980 // retrieve the forwardURI for the request
7081 HttpServletRequest . metaClass. getForwardURI = {->
0 commit comments