They are pretty much doing the same thing by adding the error messages to the container object(ActionMessages), and store the container object to the request's attribute name Globals.ERROR_KEY.
Here is a different:
The addErrors() method will append the error messages to the ActionMessages object if the ActionMessages object existed in the request object.
The saveErrors() method will replace the existing ActionMessages object with the new one that is passing in as an arugment to the method, instead of append it.
Here is a example showing the code fragment of their implemntation:
addErrors(HttpServletRequest request, ActionMessages errors)
{
// ....
ActionMessages requestErrors = (ActionMessages)request.getAttribute(Globals.ERROR _KEY);
if (requestErrors == null) {
requestErrors = new ActionMessages();
}
requestErrors.add(errors);
// ....
}
saveErrors(HttpServletRequest request, ActionMessages errors)
{
//.....
request.setAttribute(Globals.ERROR_KEY, errors);
}
Hope this help.
|