--
Ross A. Baker
ba...@alumni.indiana.edu
Indianapolis, IN, USA
From looking at the code I think that this is intentional, but wanted to double check that it's not a bug. If not, if there a way to share a flash context between filters or is it recommended to use a single filter for everything?
Thanks,
Craig
Multiple filters are reasonable. Some other options to split your
routes are discussed at
http://groups.google.com/group/scalatra-user/browse_thread/thread/ab3a097f7aea4686.
Thanks,
Craig
get (Login) {
flash += ("error" -> "this is an error")
info("flash is empty: " + flash.isEmpty)
.
.
.
}
...results in "flash is empty: true" in the log output.
Any ideas?
Thanks,
Craig
On Jun 7, 2011, at 1:52 PM, Ross A. Baker wrote:
scala> val flash = new FlashMap("demo")
flash: org.scalatra.FlashMap = Map()
scala> flash += ("error" -> "this is an error")
res7: flash.type = Map()
scala> flash.get("error")
res8: Option[Any] = None
scala> flash.sweep()
scala> flash.get("error")
res10: Option[Any] = Some(this is an error)
To make it visible for this request, you can use flash.now:
scala> val flash = new FlashMap("demo")
flash: org.scalatra.FlashMap = Map()
scala> flash.now += ("error" -> "this is an error")
res11: scala.collection.mutable.Map[String,Any] = Map(error -> this is an error)
scala> flash.get("error")
res12: Option[Any] = Some(this is an error)
scala> flash.sweep()
scala> flash.get("error")
res14: Option[Any] = None
There are a lot of flash implementations for Ruby, so the right
default behavior is highly debatable. Comments welcome, especially if
someone has an extensive Sinatra + flash scope background.
I've used the flash scope previously in Grails, where (if I remember correctly) values set are available for both the current request and the next one. This makes sense to me since the component setting the message may not always know if the next page will be rendered vs. redirected. Are there many cases where the alternative (only visible in the next request) is helpful or necessary?
Cheers,
Craig
Summary:
1) Flash entries are now available to the current request as well as the next.
2) Entries will not be swept until they are read, unless you override
sweepUnusedFlashEntries.
Details:
https://github.com/scalatra/scalatra/commit/8a66ee58e59709c5068ccf19ded6c5682fb4c106
https://github.com/scalatra/scalatra/commit/743d748328377edc5db1280289f7f459e7859993