I am trying to set a variable in a gsp page that can be found by a grails filter that I have setup (after action). I have tried the following:
_adminWarning.gsp
<div class="warning">
<g:set var="errorCode" value="403" scope="flash"/>
<h1>You are not an authorized administrator. Please contact ...</h1>
</div>
MyFilter.groovy
...
def filters = {
addHeader(controller:'capability',action:'*') {
before = {}
after = { Map model ->
// def xxx = flash.findAll{ item -> item.length() > 0}
def errCode = flash.find{ it.Key == "errorCode" } ?.value
...
}
afterView = {Exception e -> }
}
It appears that the contents of flash is empty and I am trying to figure out what I am doing wrong. We are using Grails 2.4.0
A little background here as you might see a better way of doing this. We have inherited a grail project whereby some static scaffolding pages have been generated and an attempt had been made to lock down that page. if the user wasn't an administrator, we would display a warning shown above otherwise we'll display the domain object as defined by the scaffolding code:
<g:set var="admin"
value="${...MyController.isAdmin(...myService.loggedInUser())}"/>
<g:if test="${admin==false}"/g>
<g:render template="../layout/adminWarning"/g>
</g:if>
<g:else>
// ...Continuation of scaffolding code to display a domain object
</g:else>
The only issue here is that the status code is '200' and we need the status code to be set to a '403'. Ideally I'd really like to do this test in the controller but in some cases, we don't have a controller defined (scaffolding code). So the crux of the issue is how do we set a variable in the gsp page such that the filter can easily detect t set a header that will contain a 403 response. Thanks.