- Getting started
When applying the Post/Redirect/Get pattern in web application development, I run always into the same problem: how to communicate the result to the user after the redirection.
While it is a known problem and it has been resolved in other platforms (like Rails), Java does not seem to provide a simple and elegant solution.
flash-messages is an easy way to communicate flash messages after a redirection in Java web applications.
Today, you can use flash-messages in applications which use spring-mvc as web framework and Jstl to render views.
In future releases, it will be possible to use it in JavaEE applications and possibly with another view technologies like Thymeleaf or Freemarker.
- Seamless integration with
@ExceptionHandlermethods in the spring-mvc framework
- Different levels of messages (ie. SUCCESS, INFO, WARNING, ERROR)
- Resolution of i18n messages with arguments
- Resolution of i18n arguments (ie Text, Link)
- Easy integration with the Twitter Bootstrap alerts
Get it into your project
Bill Of Materials (BOM)
flash-messages artifacts are in Maven Central and includes a BOM (Bill Of Materials) to facilitate the use of its modules.
After importing the BOM in your
pom.xml you can easily declare the modules.
You can download the latest version directly from GitHub:
Building from sources
You can build the latest version directly from source. Just run:
flash-messages is configured using spring JavaConfig. It has been tested with versions greater or equal than 3.2.6.RELEASE.
In order to obtain the default configuration, just add
@EnableFlashMessages in a
@Configuration class (the same with
@EnableWebMvc should be enough).
To modify the default behavior of flash-messages just extend
FlashMessagesConfigurerAdapter and override those methods that you want to customize.
The main elements that can be configured or customized are: levels of messages, the css classes applied to the levels, the strategy to resolve i18n messages or modify the scope where messages are stored.
In order to write messages, just declare an argument of type
Flash in the handler method (or in a
@ExceptionHandler method), then you can add messages to the different levels.
Finally, you must to include the
<flash:messages /> taglib in your views (or better in your decorator template).