+1 Now thats spooky. Before I read your msg I was outside having a smoke and thinking along exactly the same lines!
ActionForwards have evolved into something of a generic URL wrapper class for struts, and this change would be quite useful in this regard. The way Id envisaged it was that you could set the query parameters in a similar manner to those on a request: ActionForward forward = mapping.findForward("editThing").clone(); forward.setQueryParameter("pid",pageSrno"); return forward; In terms of elegance this seems nicer than what Im doing right now: ActionForward forward = mapping.findForward("editThing").clone(); return new ActionForward( appendParam(forward.getPath,"pid",pageSrno), forward.getRedirect()); This thought also lead to another thought: ActionForwards whose path is specified in the form of another ActionForward but whose parameters (& redirect etc...) can differ. At the moment my struts config is full of 'redundant' forwards like: <forward name="editThing" path="/scooby.do?method=update"/> <forward name="viewThing" path="/scooby.do?method=view"/> <forward name="killThing" path="/scooby.do?method=exterminate"/> It would be nice to use something like: <forward name="thing" path="/scooby.do"/> <forward name="editThing" pathSrc="thing"> <query-parameter name="method" value="update"/> </forward> <forward name="viewThing" pathSrc="thing"> <query-parameter name="method" value="view"/> </forward> Then if the path needs to be changed I need only modify one forward... -----Original Message----- From: iasandcb [mailto:[EMAIL PROTECTED] Sent: Tuesday, 25 March 2003 20:33 To: [EMAIL PROTECTED] Subject: [proposal]Adding queryString property to ForwardConfig I tried to develop some application with Struts, and found that there was no Struts-like way to handle ActionForward with query string, e.g. index.jsp?pid=1. Mainly what I confronted was the following: ActionForward homeForward = new ActionForward("/portal/index.jsp?pid=" + pageSrno, true); I needed to redirect to a URL, /portal/index.jsp with pid parameter. Simultaneously, there was a global forward correspondent to the URL. <forward name="welcome" path="/portal/index.jsp" redirect="true" /> What I wanted to do is to avoid a hardcoded URL but use an appropriate ActionForward from ActionMapping. For example, ActionForward homeForward = mapping.findForward("welcome"); .. However, in this case it's not possible to attach a parameter in terms of query string. (It is evident that you can use request.setAttribute for passing data to JSPs, but when it comes to redirection, it's useless and query string is necessary for the job.) What I'd like to propose comes from a question, "What if ActionForward has some property for query string?" For instance, homeForward.setQueryString("pid=" + pageSrno); actually means "/portal/index.jsp?pid=1" by combining the global forward and a programmatic query string. For implementing this feature, I added some codes to two classes: In org.apache.struts.config.ForwardConfig protected String queryString = null; public String getQueryString() { return (this.queryString); } public void setQueryString(String queryString) { /* This property can be set dynamically, so the freezing is not demanded. if (configured) { throw new IllegalStateException("Configuration is frozen"); */ } this.queryString = queryString; } In org.apache.struts.action.RequestProcessor protected void processForwardConfig(HttpServletRequest request, HttpServletResponse response, ForwardConfig forward) throws IOException, ServletException { ... // paths not starting with / should be passed through without any processing // (ie. they're absolute) if (forwardPath.startsWith("/")) { uri = RequestUtils.forwardURL(request, forward); // get module relative uri } else { uri = forwardPath; } // Newly added part-processing queryString String queryString = forward.getQueryString(); if (queryString != null) { uri += "?" + queryString; } if (forward.getRedirect()) { // only prepend context path for relative uri if (uri.startsWith("/")) { uri = request.getContextPath() + uri; } response.sendRedirect(response.encodeRedirectURL(uri)); } else { doForward(uri, request, response); } } In conclusion, you can take advantage of global forwards and forwards in actions with redirected parameters like ActionForward homeForward = mapping.findForward("welcome"); homeForward.setQueryString("pid=" + pageSrno); Instead of ActionForward homeForward = new ActionForward("/portal/index.jsp?pid=" + pageSrno, true); If you like to get this proposal as a form of patches, I'm willing to make and submit them to bugzilla. Ias =========================================================== Lee, Changshin (Korean name) Ias (International name) Company Web Site: http://www.tmax.co.kr Personal Web Site: http://www.iasandcb.pe.kr --------------------------------------------------------- Senior Researcher & Java Technology Evangelist JCP member - http://jcp.org/en/participation/members/L R&D Institute Tmax Soft, Inc. JCP member - http://jcp.org/en/participation/members/T ========================================================== --------------------------------------------------------------------- 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]