Here goes:

_________________________BEGIN______________________

/**
*
*/
package eu.goncalo.solid.presentation;

import java.util.Collection;
import java.util.Map;

import org.apache.struts2.dispatcher.DefaultActionSupport;
import org.apache.struts2.interceptor.SessionAware;

import eu.goncalo.solid.service.user.IUserView;

/**
* @author <a href="mailto:[EMAIL PROTECTED]">Goncalo Luiz</a>
*
* <br>
* <br>
* Created at 2007/02/01, 22:46:36
*/
public class SolidActionSupport extends DefaultActionSupport
implements SessionAware
{

   private static final long serialVersionUID = 2812322910038417076L;

   private enum WEBKEYS
   {
       USER_VIEW, ACTION_MESSAGE, ACTION_ERROR;
   }

   private Map<WEBKEYS, Object> session;

   @SuppressWarnings("unchecked")
   public void setSession(Map session)
   {
       this.session = session;
   }

   protected void setUserView(IUserView userView)
   {
       this.session.put(WEBKEYS.USER_VIEW, userView);
   }

   protected IUserView getUserView()
   {
       return (IUserView) this.session.get(WEBKEYS.USER_VIEW);
   }

   protected void clearSession()
   {
       this.session.clear();
   }

   @Override
   public void addActionError(String anErrorMessage)
   {
       super.addActionError(anErrorMessage);
       this.session.put(WEBKEYS.ACTION_ERROR, super.getActionErrors());
   }

   @Override
   public void addActionMessage(String aMessage)
   {
       super.addActionMessage(aMessage);
       this.session.put(WEBKEYS.ACTION_MESSAGE, super.getActionMessages());
   }

   private void clearErrors()
   {
       this.session.remove(WEBKEYS.ACTION_ERROR);
   }

   private void clearMessages()
   {
       this.session.remove(WEBKEYS.ACTION_MESSAGE);
   }

   @Override
   public void clearErrorsAndMessages()
   {
       this.session.remove(WEBKEYS.ACTION_ERROR);
       this.session.remove(WEBKEYS.ACTION_MESSAGE);
       super.clearErrorsAndMessages();
   }

   @Override
   public Collection getActionErrors()
   {
       Collection errors =  (Collection)
this.session.get(WEBKEYS.ACTION_ERROR);
       this.clearErrors();
       return errors;
   }

   @Override
   public Collection getActionMessages()
   {
       Collection messages =  (Collection)
this.session.get(WEBKEYS.ACTION_MESSAGE);
       this.clearMessages();
       return messages;
   }
}

_________________________END______________________

On 01/02/07, Dave Newton <[EMAIL PROTECTED]> wrote:
--- Gonçalo Luiz <[EMAIL PROTECTED]> wrote:
> I think it does not make sense because many messages
> that are presented are originated in the previous
> interaction.

Well, that's what session is for, I guess.

> Just inherit your actions from this class and do
> things normally... the messages will be
automatically
> persisted into session _until they are displayed_
> (that is, until the _get_ method is invoked).

The list doesn't accept attachments, but I'm not sure
how this would work, unless it's just a getter that
accesses something via a known key in a SessionAware
action (like :flash in RoR).

d.




____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail.yahoo.com



--
Gonçalo Luiz

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to