i found this class a while ago on this list it works great, just create a
parameter action forward and then add
params

forward.addParameter("name", "value");
return forward;



import java.util.HashMap;
import java.util.Iterator;



public final class ParameterActionForward extends ActionForward {

    private static final String questionMark = "?";
    private static final String ampersand = "&";
    private static final String equals = "=";
    private HashMap parameters = new HashMap();
    private String path;

    
    public ParameterActionForward(ActionForward forward) {
        setName(forward.getName());
        setPath(forward.getPath());
        setRedirect(forward.getRedirect());

    }

    
    public void setPath(String path) {
        this.path = path;

    }


    
    public String getPath() {

        StringBuffer sb = new StringBuffer();

        sb.append(path);

        boolean firstTimeThrough = true;

        if (parameters != null && !parameters.isEmpty()) {
            sb.append(questionMark);

            Iterator it = parameters.keySet()
                                    .iterator();

            while (it.hasNext()) {

                String paramName = (String)it.next();
                String paramValue = (String)parameters.get(paramName);

                if (firstTimeThrough) {
                    firstTimeThrough = false;
                } else {
                    sb.append(ampersand);
                }

                sb.append(paramName);
                sb.append(equals);
                sb.append(paramValue);

            }
        }

        return sb.toString();
    }


   
    public void addParameter(String paramName, Object paramValue) {
        addParameter(
            paramName,
            paramValue.toString());

    }

    public void addParameter(String paramName, String paramValue) {
        parameters.put(paramName, paramValue);

    }
}

-----Original Message-----
From: Jay Glanville [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 16, 2004 2:12 PM
To: 'Struts Users Mailing List'
Subject: RE: What is the best way to pass a parameter to a forward?


Latest stable release: 1.1

--
Jay Glanville


> -----Original Message-----
> From: news [mailto:[EMAIL PROTECTED] On Behalf Of Martin Cooper
> Sent: Tuesday, March 16, 2004 1:33 PM
> To: [EMAIL PROTECTED]
> Subject: Re: What is the best way to pass a parameter to a forward?
> 
> 
> 
> "Jay Glanville" <[EMAIL PROTECTED]> wrote 
> in message
> news:[EMAIL PROTECTED]
> > It's funny that you say that it will not work, because it 
> does for me,
> > and without throwing any exceptions.
> 
> What version of Struts are you using? It's not supposed to 
> work, at least
> with the latest code, so I'd like to find out whether we have 
> a bug, or
> you're using a version prior to the forwards being frozen.
> 
> --
> Martin Cooper
> 
> 
> >
> > That being said, your point about modifying an action 
> mappings forwards
> > is a good one.  It is unfortunate that the ActionForward 
> class doesn't
> > have a copy constructor ....
> >
> > --
> > Jay Glanville
> >


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

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

Reply via email to