DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6686>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6686 make "action" attribute of html:form tag optional w/default = URL launching it ------- Additional Comments From [EMAIL PROTECTED] 2002-03-04 20:40 ------- These two patches, when applied to ActionServlet.java and FormTag.java, enable the requested functionality. The "action" attribute is still required by the html:form tag (unless the taglib's tld file is changed to make it non-required), but the result is obtained by using a blank value for "action". Example: <html:form action="">...</html:form> The patch works by saving the value of request.getRequestURI() as a request- scope attribute named "requestedURI" in ActionServlet prior to calling perform (), and retrieving it via pageContext.findAttribute("requestedURI") in FormTag upon discovering that action is either null or blank. I can't think of any way this patch could possibly break old or naive code that's unaware of it, since it merely adds a default value where there was previously none and enables a scenario that was previously not allowed. The following should be added to the "form" tag's entry in the taglib documentation for the html taglib (http://jakarta.apache.org/struts/userGuide/struts-html.html): ... If you are using path mapping to select the controller servlet, this value should be exactly equal to the path attribute of the corresponding <action> element. If the "action" attribute is present, but blank (action=""), the "action" attribute will inherit the URI of the current request. In other words, if a form submission to "/some/action.do" results in the rendering of a jsp page containing <html:form action="">, it will be rendered as though the tag were <html:form action="/some/action.do">. The "action" parameter is still mandatory... it merely assumes a default value whenever it's blank. Both patches are attached, but I'll show them here in their proper context since they're only two lines apiece (not including comments comments and surrounding code): ActionServlet.java: protected void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // This goes at the beginning of ActionServlet's process() method; // specifically, beginning with line 1105 of revision 1.94 /* Store the requestURI's value for later potential use. Specifically, * this value is used by struts.taglib.html.getActionMappingURL() * whenever a html:form tag is created WITHOUT an explicit action * attribute because the developer wants the generated form to have * the same target URL as the current request. We need to save it here, * because by then request.getRequestURI will contain the value of the jsp * template, not the request that launched everything in the first place... * and THIS is the value we need and care about. */ String requestedURI = request.getRequestURI(); request.setAttribute("requestedURI", requestedURI); // End of new code added to beginning of process() // the remaining code is unchanged from this point forward RequestUtils.selectApplication(request, getServletContext()); getApplicationConfig(request).getProcessor().process (request, response); } FormTag.java: protected String getActionMappingURL() { // This goes at the beginning of the getActionMappingURL() method; // Specifically, line 752 of revision 1.18 /* If action is null or blank, it's because the user omitted the "action" * attribute from the html:form tag. Presumably, the user wants the form * to be submitted to the same URL as THIS request. That value is stored * in request context by org.apache.struts.action.ActionServlet.process () * and obtained using request.getRequestURI(). Why can't we simply call * request.getRequestURI() HERE? Because by this point, the Action servlet * has already forwarded control to the jsp, and request.getRequestURI() * now holds the hypothetical URI of the jsp page being rendered, not the * URI that launched the Action servlet in the first place... and THAT'S * the one we need. * * Potential side-effects: this patch shouldn't cause anything that * explicitly specifies the "action" attribute to break, but so far its * ability to generate default actions has only been tested with one kind of * request: "/path/to/mapping.do". It specifically has NOT been tested with * requests that involve URL-encoded GET formvars, nor has it been tested * with cookie session tracking disabled. */ if ((action == null) || (action.length() == 0)) { action = (String)pageContext.findAttribute("requestedURI"); } // End of new code added to beginning of getActionMappingURL() // the remaining code is unchanged from this point forward. HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); StringBuffer value = new StringBuffer(request.getContextPath()); ApplicationConfig config = (ApplicationConfig) pageContext.getRequest().getAttribute(Action.APPLICATION_KEY); if (config != null) { value.append(config.getPrefix()); } -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>