Return-Path: Delivered-To: apmail-struts-dev-archive@www.apache.org Received: (qmail 69883 invoked from network); 17 Jun 2004 21:58:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 17 Jun 2004 21:58:22 -0000 Received: (qmail 63890 invoked by uid 500); 17 Jun 2004 21:58:37 -0000 Delivered-To: apmail-struts-dev-archive@struts.apache.org Received: (qmail 63856 invoked by uid 500); 17 Jun 2004 21:58:36 -0000 Mailing-List: contact dev-help@struts.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Struts Developers List" Reply-To: "Struts Developers List" Delivered-To: mailing list dev@struts.apache.org Received: (qmail 63837 invoked by uid 99); 17 Jun 2004 21:58:36 -0000 Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Thu, 17 Jun 2004 14:58:36 -0700 Received: (qmail 69791 invoked from network); 17 Jun 2004 21:58:12 -0000 Received: from unknown (HELO minotaur.apache.org) (127.0.0.1) by 127.0.0.1 with SMTP; 17 Jun 2004 21:58:12 -0000 Content-Type: text/plain; charset="iso-8859-1" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: dev@struts.apache.org To: dev@struts.apache.org Subject: =?iso-8859-1?q?=5BApache_Struts_Wiki=5D_Updated=3A__ForwardingWithDiffere?= =?iso-8859-1?q?ntParameter?= Date: Thu, 17 Jun 2004 21:58:12 -0000 Message-ID: <20040617215812.69775.1920@minotaur.apache.org> X-Spam-Rating: 127.0.0.1 1.6.2 0/1000/N X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Date: 2004-06-17T14:58:11 Editor: MarkDiggory Wiki: Apache Struts Wiki Page: ForwardingWithDifferentParameter URL: http://wiki.apache.org/struts/ForwardingWithDifferentParameter no comment Change Log: ---------------------------------------------------------------------------= --- @@ -96,3 +96,75 @@ = = = +How about a Wrapper class like below that provideds Parameter copying func= tionality? - Mark Diggory + +{{{ + +package edu.harvard.hmdc.curate.study; + +import java.util.Enumeration; +import java.util.Hashtable; +import java.net.URLEncoder; +import javax.servlet.http.HttpServletRequest; +import org.apache.struts.action.ActionForward; + +public class MyActionForward extends ActionForward { + + private Hashtable parameters =3D new Hashtable(); + = + public MyActionForward(ActionForward forward) { + super(forward.getName(),forward.getPath(),forward.getRedirect(),fo= rward.getContextRelative()); + } + = + public MyActionForward(ActionForward forward, HttpServletRequest reque= st) { + super(forward.getName(),forward.getPath(),forward.getRedirect(),fo= rward.getContextRelative()); + parameters.putAll(request.getParameterMap()); + } + + public void addParameter(String name, String value) { + String[] newValues =3D null; + String[] oldValues =3D (String[]) parameters.get(name); + if (oldValues =3D=3D null) { + newValues =3D new String[1]; + newValues[0] =3D value; + } else { + newValues =3D new String[oldValues.length + 1]; + System.arraycopy(oldValues, 0, newValues, 0, oldValues.length); + newValues[oldValues.length] =3D value; + } + parameters.put(name, newValues); + } + = + public String getPath() { + String result =3D super.getPath(); + = + if(!parameters.isEmpty()) + result +=3D "?"; + + for(Enumeration enum =3D parameters.keys();enum.hasMoreElements();= ){ + String next =3D (String)enum.nextElement(); + String[] vals =3D (String[])parameters.get(next); + = + for(int i =3D 0; i < vals.length;i++){ + if(vals[i] !=3D null){ + result +=3D next; + result +=3D "=3D"; + result +=3D URLEncoder.encode(vals[i]); + = + if(i <=3D vals.length) + result +=3D "&"; + } + } + = + if(enum.hasMoreElements()) + result +=3D "&"; + } + = + return result; + } + = +} + + +}}} + --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org For additional commands, e-mail: dev-help@struts.apache.org