struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gonçalo Luiz" <goncalo.l...@gmail.com>
Subject Re: ActionMessage/ActionError and redirect-action result
Date Thu, 01 Feb 2007 23:49:04 GMT
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:goncalo@goncalo.eu">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 <newton.dave@yahoo.com> wrote:
> --- Gonçalo Luiz <goncalo.luiz@gmail.com> 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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message