Grails Webflow Scope and View Issues

Friday, July 31, 2009 by Brandon Comments

  I ran into an annoying problem while developing a Grails application.  I could create a message in flash scope and display it in view in a normal controller, but that same flash message would not appear if I was inside a webflow.  The variable would just be null.  I finally found the reason for this after reading a ton of Grails documentation. Apparently, a webflow in Grails actually merges all the flash, flow, and conversation scoped variables into the Model view before rendering it.  So you shouldn’t reference variables in the view by scope, instead you should reference them just by name.

For example, instead of writing this in your GSP view:

<g:if test="${flash.message}">
<div class="message">${flash.message}</div>
</g:if>

You would just write this:

<g:if test="${message}">
<div class="message">${message}</div>
</g:if>
blog comments powered by Disqus