In the base layout, i have the following code to show the cart count.
<g:if test="${session['products-ids']}">
<g:link elementId="cart-link" controller="payment" action="productsPurchaseSummary">
<div id="cart-image">
<span id="cart-count">
<%
println session['products-ids'].split(",").size()
%>
</span>
</div>
</g:link>
</g:if>
This code is throwing error at the point when session['products-ids'] is checked. The error is as follows:
Caused by: java.lang.IllegalStateException: Cannot create a session after the response has been committed
at C__Users_Lenovo_IdeaProjects_grails_app_views_layouts__cart_gsp.run(C__Users_Lenovo_IdeaProjects_grails_app_views_layouts__cart_gsp:19)
... 5 more
When i donot access the session then the view renders. So i wonder whether there is a way to access session in view safely. I am using Grails 2.2. Thanks for the help!