You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by "Mark R. Diggory" <md...@latte.harvard.edu> on 2004/06/23 19:25:15 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



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);
>>
typo, clearly this should be request.getAttribute(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
>
>
>------------------------------------------------------------------------
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
>For additional commands, e-mail: dev-help@struts.apache.org
>



Re: saveErrors...

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

>> 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.
>
>
> I wouldn't object to having "addErrors" methods which do this, but I 
> think it would be wrong to change the behavior of saveErrors to no 
> longer remove existing messages.  Same, of course, goes for 
> addMessages/saveMessages
>
> Joe
>
I agree, all I've done for myself is implement "saveError" and 
"saveMessage" methods which do this in my Action base class. So it could 
easily be something like an addition of these methods with a possible 
deprecation of saveErrors/Messages sometime over future versions.

Mostly, I'm just presenting things I find useful while I'm working with 
the library.
-Mark


Re: saveErrors...

Posted by Joe Germuska <Jo...@Germuska.com>.
>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.

I wouldn't object to having "addErrors" methods which do this, but I 
think it would be wrong to change the behavior of saveErrors to no 
longer remove existing messages.  Same, of course, goes for 
addMessages/saveMessages

Joe

-- 
Joe Germuska            
Joe@Germuska.com  
http://blog.germuska.com    
"In fact, when I die, if I don't hear 'A Love Supreme,' I'll turn 
back; I'll know I'm in the wrong place."
    - Carlos Santana

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org