Home Grails setting a variable in a gsp page that can be found by a filter (after)

# Grails setting a variable in a gsp page that can be found by a filter (after)

user2110
1#
user2110 Published in June 19, 2018, 2:43 pm
 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

 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:  // ...Continuation of scaffolding code to display a domain object  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.