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

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

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:

    <div class="warning">
        <g:set var="errorCode" value="403" scope="flash"/>
        <h1>You are not an authorized administrator. Please contact ...</h1>


    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" 
 <g:if test="${admin==false}"/g>
     <g:render template="../layout/adminWarning"/g>
    // ...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.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.347146 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO