You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by "Mark R. Diggory" <md...@latte.harvard.edu> on 2004/06/23 19:10:58 UTC

saveErrors...

I was looking at the code for Action.saveErrors(...) and was think this 
is a little inflexible when it comes to error and message management:

>     protected void saveErrors(HttpServletRequest request, 
> ActionMessages errors) {
>
>         // Remove any error messages attribute if none are required
>         if ((errors == null) || errors.isEmpty()) {
>             request.removeAttribute(Globals.ERROR_KEY);
>             return;
>         }
>
>         // Save the error messages we need
>         request.setAttribute(Globals.ERROR_KEY, errors);
>
>     }


If I have errors occur in different locations, rather than returning 
ActionMessages objects and having to merge them myself prior to calling 
"saveErrors" or "saveMessages", why not have this be more like 
"addError" or "addMessage" at the action level so that the user doesn't 
need to maintain the "ActionMessages" object themselves? As well they 
can call saveError almost anywhere in the code without overwriting the 
existing errors object, which is "saveErrors" existing behavior.

>    ...
>
>    saveError(request,"foo", new ActionMessage("foo.bar"));
>
>    ...
>
>     protected void saveError(HttpServletRequest request, String key, 
> ActionMessage error) {
>
>        ActionMessages errors = (ActionMessages) 
> request.removeAttribute(Globals.ERROR_KEY);
>
>         // Remove any error messages attribute if none are required
>         if ((errors == null)) {
>               errors = new ActionMessages();
>         }
>
>          errors.add(key, error);
>
>          request.setAttribute(Globals.ERROR_KEY, errors);
>
>     }

-Mark Diggory


Please IGNORE, This post is to the wrong list (was Re: saveErrors...)

Posted by "Mark R. Diggory" <md...@latte.harvard.edu>.
Mark R. Diggory wrote:

> I was looking at the code for Action.saveErrors(...) and was think 
> this is a little inflexible when it comes to error and message 
> management:
>
>>     protected void saveErrors(HttpServletRequest request, 
>> ActionMessages errors) {
>>
>>         // Remove any error messages attribute if none are required
>>         if ((errors == null) || errors.isEmpty()) {
>>             request.removeAttribute(Globals.ERROR_KEY);
>>             return;
>>         }
>>
>>         // Save the error messages we need
>>         request.setAttribute(Globals.ERROR_KEY, errors);
>>
>>     }
>
>
>
> If I have errors occur in different locations, rather than returning 
> ActionMessages objects and having to merge them myself prior to 
> calling "saveErrors" or "saveMessages", why not have this be more like 
> "addError" or "addMessage" at the action level so that the user 
> doesn't need to maintain the "ActionMessages" object themselves? As 
> well they can call saveError almost anywhere in the code without 
> overwriting the existing errors object, which is "saveErrors" existing 
> behavior.
>
>>    ...
>>
>>    saveError(request,"foo", new ActionMessage("foo.bar"));
>>
>>    ...
>>
>>     protected void saveError(HttpServletRequest request, String key, 
>> ActionMessage error) {
>>
>>        ActionMessages errors = (ActionMessages) 
>> request.removeAttribute(Globals.ERROR_KEY);
>>
>>         // Remove any error messages attribute if none are required
>>         if ((errors == null)) {
>>               errors = new ActionMessages();
>>         }
>>
>>          errors.add(key, error);
>>
>>          request.setAttribute(Globals.ERROR_KEY, errors);
>>
>>     }
>
>
> -Mark Diggory