What’s the best way to achieve Rails-like flash messages such as ‘Update successful’ http://api.rubyonrails.org/classes/ActionController/Flash.html) in the Java world? I’m using Spring MVC.
What’s the best way to achieve Rails-like flash messages such as Update successful http://api.rubyonrails.org/classes/ActionController/Flash.html
Share
I would recommend implementing this as a session-wide HashTable, with string keys mapping to custom FlashItem objects. The FlashItem will simply contain the object or string you’re storing plus a boolean value, possibly called IsNew, which should be set to true when you insert a new item into the HashTable.
On each page load you then iterate the HashTable, set any IsNew = true items to false, and delete any items where IsNew is already false. That should give you a work-alike to Rails’s flash feature.