Using the <set> tag in grails

I am new to grails. I came across a set tag that we can use in the gsp pages themselves to set values ​​similar to the installation model from the controller.

<g:set var="home" value="something" /> 

so when we write $ {home}, it prints "something."

Is it possible to set the value in sessions directly on gsp pages, and not on the controller using the set tag?

+6
source share
2 answers

Yes, you can do this on gsp pages as well. You just need to include an additional attribute area to indicate which areas (session, flash, page, and request) you are setting the value.

 <g:set var="home" value="something" scope="session" /> 

If you did not enable the area option, then the default page is used.

To display the value, you just need to write $ {session.home} or $ {request.home} or just $ {home} for the request area. Hope this helps.

Additional information: https://grails.imtqy.com/grails-doc/3.0.x/ref/tags/set.html

+6
source

Well! Above answer is enough need. I just wanted to add one more thing that contains gsp pages from jsp inside, and, therefore, all 9 implict objects are available on gsp pages.

 request HttpServletRequest object response HttpServletResponse object out PrintWriter object used to send output to the client. session HttpSession object application ServletContext object associated with application context. config ServletConfig object associated with the page. pageContext server-specific features JspWriters. page synonym for this Exception handling exceptions and error page redirects.An instance of javax.servlet.jsp.JspException 

At any given time, you can access these pages on the gsp pages.

You can read more from this .

Hope this helps!

0
source

All Articles