Author: niallp Date: Mon May 8 16:06:48 2006 New Revision: 405216 URL: http://svn.apache.org/viewcvs?rev=405216&view=rev Log: Fix for STR-2795 - Postback Forms - caching and modules.
Added: struts/action/trunk/apps/examples/src/main/webapp/exercise/html-form.jsp (with props) Modified: struts/action/trunk/apps/examples/src/main/webapp/WEB-INF/exercise/struts-config.xml struts/action/trunk/apps/examples/src/main/webapp/exercise/index.html struts/action/trunk/src/site/xdoc/userGuide/release-notes.xml struts/action/trunk/taglib/src/main/java/org/apache/struts/taglib/html/FormTag.java Modified: struts/action/trunk/apps/examples/src/main/webapp/WEB-INF/exercise/struts-config.xml URL: http://svn.apache.org/viewcvs/struts/action/trunk/apps/examples/src/main/webapp/WEB-INF/exercise/struts-config.xml?rev=405216&r1=405215&r2=405216&view=diff ============================================================================== --- struts/action/trunk/apps/examples/src/main/webapp/WEB-INF/exercise/struts-config.xml (original) +++ struts/action/trunk/apps/examples/src/main/webapp/WEB-INF/exercise/struts-config.xml Mon May 8 16:06:48 2006 @@ -77,6 +77,10 @@ name="testbean" scope="session" validate="false"> <forward name="input" path="/html-setters.do"/> </action> + <action path="/html-form" forward="/html-form.jsp" + name="testbean" scope="session" validate="false"/> + <action path="/html-form-postback" forward="/html-form.jsp" + name="testbean" scope="session" validate="false"/> <action path="/logic-forward" forward="/logic-forward.jsp"/> <action path="/logic-forward-test-forward" forward="/logic-forward-test-forward.jsp"/> Added: struts/action/trunk/apps/examples/src/main/webapp/exercise/html-form.jsp URL: http://svn.apache.org/viewcvs/struts/action/trunk/apps/examples/src/main/webapp/exercise/html-form.jsp?rev=405216&view=auto ============================================================================== --- struts/action/trunk/apps/examples/src/main/webapp/exercise/html-form.jsp (added) +++ struts/action/trunk/apps/examples/src/main/webapp/exercise/html-form.jsp Mon May 8 16:06:48 2006 @@ -0,0 +1,49 @@ +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> +<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> +<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %> +<html:html> + <head> + <title> + <title>Test struts-html:form Tag</title> + </title> + <html:base/> + </head> + + <body bgcolor="white"> + + <p><strong><i>Post Back</i> Form example</strong></p> + + <p> + Pressing the Submit button should re-display this page. + </p> + + <logic:messagesPresent> + <p> + <font color="red"><strong> + <html:messages id="msg"> + <bean:write name="msg"/> + </html:messages> + </strong></font> + </p> + </logic:messagesPresent> + + <p> + <html:form> + <html:submit property="submit"/> + </html:form> + </p> + <p> + Use the links below to change the <i>postback</i> action (both return + to this page). + <ul> + <li>Switch to <html:link action="html-form">/html-form</html:link></li> + <li>Switch to <html:link action="html-form-postback">/html-form-postback</html:link></li> + </ul> + </p> + <hr/> + + <p><html:link action="welcome">Return to the Taglib Exercises main page</html:link></p> + + </body> +</html:html> Propchange: struts/action/trunk/apps/examples/src/main/webapp/exercise/html-form.jsp ------------------------------------------------------------------------------ svn:eol-style = native Propchange: struts/action/trunk/apps/examples/src/main/webapp/exercise/html-form.jsp ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Modified: struts/action/trunk/apps/examples/src/main/webapp/exercise/index.html URL: http://svn.apache.org/viewcvs/struts/action/trunk/apps/examples/src/main/webapp/exercise/index.html?rev=405216&r1=405215&r2=405216&view=diff ============================================================================== --- struts/action/trunk/apps/examples/src/main/webapp/exercise/index.html (original) +++ struts/action/trunk/apps/examples/src/main/webapp/exercise/index.html Mon May 8 16:06:48 2006 @@ -58,6 +58,8 @@ <li><a href="html-messages.do">Errors and Messages</a></li> + <li><a href="html-form.do"><html:form></a></li> + <li>Other html tags [:TODO:]</li> </ul> Modified: struts/action/trunk/src/site/xdoc/userGuide/release-notes.xml URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/site/xdoc/userGuide/release-notes.xml?rev=405216&r1=405215&r2=405216&view=diff ============================================================================== --- struts/action/trunk/src/site/xdoc/userGuide/release-notes.xml (original) +++ struts/action/trunk/src/site/xdoc/userGuide/release-notes.xml Mon May 8 16:06:48 2006 @@ -158,6 +158,7 @@ <li>[<a href='http://issues.apache.org/struts/browse/STR-2741'>STR-2741</a>] - [site] Broken Links</li> <li>[<a href='http://issues.apache.org/struts/browse/STR-2752'>STR-2752</a>] - forwardPattern implementation missing</li> <li>[<a href='http://issues.apache.org/struts/browse/STR-2793'>STR-2793</a>] - Postback form (optional 'action' attribute for html-el:form) is not working</li> +<li>[<a href='http://issues.apache.org/struts/browse/STR-2795'>STR-2795</a>] - Postback Forms - caching and modules</li> <li>[<a href='http://issues.apache.org/struts/browse/STR-2805'>STR-2805</a>] - java.lang.NullPointerException</li> <li>[<a href='http://issues.apache.org/struts/browse/STR-2809'>STR-2809</a>] - ImportAttribute does not import all attribute with ignore=true</li> <li>[<a href='http://issues.apache.org/struts/browse/STR-2826'>STR-2826</a>] - If a field's display property is set to 'none' using CSS or JavaScript, the focus code fails.</li> Modified: struts/action/trunk/taglib/src/main/java/org/apache/struts/taglib/html/FormTag.java URL: http://svn.apache.org/viewcvs/struts/action/trunk/taglib/src/main/java/org/apache/struts/taglib/html/FormTag.java?rev=405216&r1=405215&r2=405216&view=diff ============================================================================== --- struts/action/trunk/taglib/src/main/java/org/apache/struts/taglib/html/FormTag.java (original) +++ struts/action/trunk/taglib/src/main/java/org/apache/struts/taglib/html/FormTag.java Mon May 8 16:06:48 2006 @@ -41,8 +41,7 @@ * Custom tag that represents an input form, associated with a bean whose * properties correspond to the various fields of the form. * - * @version $Rev$ $Date: 2005-06-22 12:23:18 -0400 (Wed, 22 Jun 2005) - * $ + * @version $Rev$ $Date$ */ public class FormTag extends TagSupport { /** @@ -65,6 +64,11 @@ protected String action = null; /** + * A postback action URL to which this form should be submitted, if any. + */ + private String postbackAction = null; + + /** * The module configuration for our module. */ protected ModuleConfig moduleConfig = null; @@ -406,6 +410,9 @@ * @throws JspException if a JSP exception has occurred */ public int doStartTag() throws JspException { + + postbackAction = null; + // Look up the form bean name, scope, and type if necessary this.lookup(); @@ -520,12 +527,13 @@ * Renders the action attribute */ protected void renderAction(StringBuffer results) { + String calcAction = (this.action == null ? postbackAction : this.action); HttpServletResponse response = (HttpServletResponse) this.pageContext.getResponse(); results.append(" action=\""); results.append(response.encodeURL( - TagUtils.getInstance().getActionMappingURL(this.action, + TagUtils.getInstance().getActionMappingURL(calcAction, this.pageContext))); results.append("\""); @@ -615,6 +623,8 @@ throw new JspException(messages.getMessage("common.io", e.toString())); } + postbackAction = null; + // Continue processing this page return (EVAL_PAGE); } @@ -727,15 +737,6 @@ * @throws JspException if a required value cannot be looked up */ protected void lookup() throws JspException { - // If the action is not specified, use the original request uri - if (this.action == null) { - HttpServletRequest request = - (HttpServletRequest) pageContext.getRequest(); - String uri = - (String) request.getAttribute(Globals.ORIGINAL_URI_KEY); - - setAction(uri); - } // Look up the module configuration information we need moduleConfig = TagUtils.getInstance().getModuleConfig(pageContext); @@ -749,12 +750,28 @@ throw e; } + String calcAction = this.action; + + // If the action is not specified, use the original request uri + if (this.action == null) { + HttpServletRequest request = + (HttpServletRequest) pageContext.getRequest(); + postbackAction = + (String) request.getAttribute(Globals.ORIGINAL_URI_KEY); + + String prefix = moduleConfig.getPrefix(); + if (postbackAction != null && prefix.length() > 0 && postbackAction.startsWith(prefix)) { + postbackAction = postbackAction.substring(prefix.length()); + } + calcAction = postbackAction; + } + servlet = (ActionServlet) pageContext.getServletContext().getAttribute(Globals.ACTION_SERVLET_KEY); // Look up the action mapping we will be submitting to String mappingName = - TagUtils.getInstance().getActionMappingName(action); + TagUtils.getInstance().getActionMappingName(calcAction); mapping = (ActionMapping) moduleConfig.findActionConfig(mappingName); @@ -776,10 +793,10 @@ JspException e = null; if (mapping.getName() == null) { - e = new JspException(messages.getMessage("formTag.name", action)); + e = new JspException(messages.getMessage("formTag.name", calcAction)); } else { e = new JspException(messages.getMessage("formTag.formBean", - mapping.getName(), action)); + mapping.getName(), calcAction)); } pageContext.setAttribute(Globals.EXCEPTION_KEY, e,