Interesting. I found this in my old project.
(it was a basic controller, but it could well be a utility method)
protected void addMessage(String key, boolean isError, HttpServletRequest request, Object... args) { List<Message> msgs = (List<Message>) request.getAttribute(MESSAGES_KEY); if (msgs == null) { msgs = new LinkedList<Message>(); } Message msg = new Message(); msg.setMessage(msg(key, args)); msg.setError(isError); msgs.add(msg); request.setAttribute(MESSAGES_KEY, msgs); }
and then in messages.jsp , which was included in all the pages that I had:
<c:forEach items="${messages}" var="message">
MESSAGES_KEY is my constant with a value of "message" (so it is later available in a forEach loop).
The Message class is just a POJO with these two properties. I used it for informational messages, as well as for custom non-adaptation errors.
This is a rather peculiar solution, but maybe I did not find a built-in solution. Google a little more before using such a solution.
Bozho
source share