Return-Path: Delivered-To: apmail-jakarta-struts-user-archive@www.apache.org Received: (qmail 74846 invoked from network); 9 Feb 2004 09:30:03 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 9 Feb 2004 09:30:03 -0000 Received: (qmail 60044 invoked by uid 500); 9 Feb 2004 09:28:37 -0000 Delivered-To: apmail-jakarta-struts-user-archive@jakarta.apache.org Received: (qmail 60007 invoked by uid 500); 9 Feb 2004 09:28:36 -0000 Mailing-List: contact struts-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Struts Users Mailing List" Reply-To: "Struts Users Mailing List" Delivered-To: mailing list struts-user@jakarta.apache.org Received: (qmail 59858 invoked from network); 9 Feb 2004 09:28:35 -0000 Received: from unknown (HELO gridnode.com) (202.83.97.26) by daedalus.apache.org with SMTP; 9 Feb 2004 09:28:35 -0000 Received: from andrew (pc209 [192.168.213.209]) by gridnode.com (8.12.9/8.12.4) with SMTP id i199h5Vm023622 for ; Mon, 9 Feb 2004 17:43:06 +0800 Reply-To: From: "Andrew Hill" To: "Struts" Subject: RE: Need to modify the URL path of the forward dynamically Date: Mon, 9 Feb 2004 17:25:21 +0800 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 In-Reply-To: <00f401c3eeee$6d629430$6401a8c0@ebuilt.net> Importance: Normal X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N >From what Ive seen on the list, the way we are using seems to be pretty much standard practice. I did see some activity on the dev list regarding enhancing forwards to make doing this sort of thing easier, though I wasnt following closely so cant tell you what the outcome was. If its something you need to do a lot you may wish to create a method in your base action class that will take the name of a forward, some parameters to tack on, and go look up the forward and return a new instance with the parameters added to the path. I dont bother with that myself though. I do have some methods to deal with the ? vs & when tacking on the url. Heres the code (2 methods) I use to do the appending (they live in a static class where I dump lots of odds and ends like this!): ummm... the encoder bit... hmmm. You could live without that if you dont try to append funny chars. :-) hehe. The original version of the method was a one-liner. public static String addParameterToURL(String url, String parameter, String value) { try { if(value != null) value = URLEncoder.encode(value, "UTF-8"); } catch(UnsupportedEncodingException e) { throw new NestableRuntimeException("Error encoding value " + quotedString(value),e); } if(url == null) { return parameter + "=" + value; } else { return url + ( (url.indexOf("?")==-1) ? "?" : "&" ) + parameter + "=" + value; } } /** * Uses propertyutils to read parameters from source. Empty/null parameters are NOT appended. */ public static String addParametersToURL(String url, Object source, String[] parameters) { if( source == null ) return url; if( parameters == null || parameters.length == 0 ) return url; StringBuffer buffer = new StringBuffer(url == null ? "" : url); for( int i = 0; i < parameters.length; i++ ) { String parameter = parameters[i]; if( stringNotEmpty(parameter) ) { String value = null; try { value = stringValue( PropertyUtils.getProperty(source, parameter) ); } catch(Throwable t) { value = null; } if( StaticUtils.stringNotEmpty(value) ) { buffer.append( buffer.indexOf("?")==-1 ? "?" : "&" ); buffer.append(parameter); buffer.append("="); try { buffer.append(URLEncoder.encode(value, "UTF-8")); } catch(UnsupportedEncodingException e) { throw new NestableRuntimeException("Error encoding value " + quotedString(value),e); } } } } return buffer.toString(); } -----Original Message----- From: Max Cooper [mailto:max@maxcooper.com] Sent: Monday, 9 February 2004 17:24 To: Struts Users Mailing List; andrew.david.hill@gridnode.com Subject: Re: Need to modify the URL path of the forward dynamically Andrew's procedure is what my team has done on one project, too. Originally, we tried getting the ActionForward and changing it directly, but it turns out that is a shared instance and changing the original was messing up other requests. After we discovered this problem, we switched to Andrew's scheme of creating a new ActionForward to return from the Action. I posted a message today with a note about dynamically adding a query string to an ActionForward in the "URL does not change even after changing action" thread. This thread has the details about how to do that. I am interested to hear from other folks if they have a novel way to do this (i.e. add a query string to an ActionForward). Anybody got a better way? -Max ----- Original Message ----- From: "Andrew Hill" To: "Struts Users Mailing List" Sent: Monday, February 09, 2004 12:36 AM Subject: RE: Need to modify the URL path of the forward dynamically > Need to modify the URL path of the forward dynamicallyGet the Forward > instance as usual. Obtain its url string using getPath(). Add your > additional parameter to end of string and create a new ActionForward > instance that uses the decorated path (and copies the redirect property from > the original action forward), and return this new actionforward instance. > -----Original Message----- > From: Swaminathan Rajagopalan [mailto:RSwami@infosys.com] > Sent: Monday, 9 February 2004 16:34 > To: struts-dev@jakarta.apache.org; struts-user@jakarta.apache.org > Cc: Kamal_Poddar > Subject: Need to modify the URL path of the forward dynamically > > > Hi, > > We have a URL in the path attribute of a forward for an action. We need to > dynamically append some request variables to this URL in the action class, > for they are available only at execution time. How can this be achieved? > > E.g > > type="xxx.yyy.zzz.web.control.action.AdditionalAccountInfoScreenAction" > name="additionalAccountInfoForm" > validate="false" > input="previousPage" > parameter="populateStmt" > scope="session"> > > To the URL path here e.g http://www.xyz.com/checks we need to add > accessId=xxx at run time in the action > class(http://www.xyz.com/checks?accessId=xxx). > > Please let us know how this can be done? > > Regards, > Swaminathan Rajagopalan, > Ph : (8520261) Extn: 55955 > Mail : rswami@infosys.com > > --------------------------------------------------------------------- To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: struts-user-help@jakarta.apache.org