In our application we a cannot use SessionScope excet for exceptional circumstances so I have added the code as follows. The Controllers that typically ( but not neccesarily)generate the messages are FormControllers
Code:
public class UIManager
public static final getSuccessMessages(request)
{
List messages = (List)req.getAttribute(ModelParameter.MESSAGES);
if (messages == null)
{
messages = new ArrayList();
req.setAttribute(ModelParameter.MESSAGES, messages);
}
return (messages);
}
....Method from a Typical AbstractFormController
Code:
ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
BindException errors) throws Exception
{
try
{
widgetbean.createWidget(widgetVO);
UIManager.getSuccessMessages(request).add(getMessageSourceAccessor().getMessage("success.1"));
}
catch (BusinessException be)
{
return this.showForm(request, response, errors);
}
}
...Calling Controller, always check for data in the ModelParameter.MESSAGES session attribute
Code:
myModel.put(ModelParameter.MESSAGES, request.getAttribute(ModelParameter.MESSAGES));
... JSPs always check and display data accordingly
Code:
<c:forEach items="${model.messages}" var="message">
<h3 class="generalsuccess"><c:out value="${message}"/></font></h3>
</c:forEach>
It would be nice if there was a clearly defined way of doing this