Revision: 614
          http://stripes.svn.sourceforge.net/stripes/?rev=614&view=rev
Author:   bengunter
Date:     2007-10-09 21:38:07 -0700 (Tue, 09 Oct 2007)

Log Message:
-----------
Fixed STS-424: stripes:form should allow stripes:param tags. stripes:param tags 
can now be used to append parameters to the form's action attribute. This was 
specifically intended to support clean URLs, but it also will append parameters 
to the query string for normal URLs.

Modified Paths:
--------------
    trunk/stripes/src/net/sourceforge/stripes/tag/FormTag.java

Modified: trunk/stripes/src/net/sourceforge/stripes/tag/FormTag.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/tag/FormTag.java  2007-10-09 
23:03:31 UTC (rev 613)
+++ trunk/stripes/src/net/sourceforge/stripes/tag/FormTag.java  2007-10-10 
04:38:07 UTC (rev 614)
@@ -22,6 +22,7 @@
 import net.sourceforge.stripes.util.CryptoUtil;
 import net.sourceforge.stripes.util.HtmlUtil;
 import net.sourceforge.stripes.util.Log;
+import net.sourceforge.stripes.util.UrlBuilder;
 import net.sourceforge.stripes.validation.ValidationErrors;
 import net.sourceforge.stripes.validation.ValidationError;
 
@@ -45,7 +46,7 @@
  *
  * @author Tim Fennell
  */
-public class FormTag extends HtmlTagSupport implements BodyTag, 
TryCatchFinally {
+public class FormTag extends HtmlTagSupport implements BodyTag, 
TryCatchFinally, ParameterizableTag {
     /** Log used to log error and debugging information for this class. */
     private static final Log log = Log.getInstance(FormTag.class);
 
@@ -57,6 +58,9 @@
     /** Stores the value of the action attribute before the context gets 
appended. */
     private String actionWithoutContext;
 
+    /** Builds the action attribute with parameters */
+    private UrlBuilder urlBuilder;
+
     /** A map of field name to field type for all fields registered with the 
form. */
     private Map<String,Class> fieldsPresent = new HashMap<String,Class>();
 
@@ -79,18 +83,6 @@
         else {
             this.actionWithoutContext = action;
         }
-
-        if (action.startsWith("/")) {
-            HttpServletRequest request = (HttpServletRequest) 
getPageContext().getRequest();
-            String contextPath = request.getContextPath();
-
-            if (contextPath != null && !"/".equals(contextPath) && 
!action.contains(contextPath + "/")) {
-                action = contextPath + action;
-            }
-        }
-
-        HttpServletResponse response = (HttpServletResponse) 
getPageContext().getResponse();
-        set("action", response.encodeURL(action));
     }
 
     public String getAction() { return this.actionWithoutContext; }
@@ -172,6 +164,7 @@
                     + "action bean should handle the form submission.");
         }
         getTagStack().push(this);
+        urlBuilder = new UrlBuilder(pageContext.getRequest().getLocale(), 
getAction(), false);
         return EVAL_BODY_BUFFERED;
     }
 
@@ -204,6 +197,8 @@
                 setMethod("post");
             }
 
+                       set("action", buildAction());
+
             JspWriter out = getPageContext().getOut();
             if (!isPartial()) {
                 writeOpenTag(out, "form");
@@ -421,4 +416,37 @@
     public Set<String> getRegisteredFields() {
         return this.fieldsPresent.keySet();
     }
+
+    /**
+     * Appends a parameter to the "action" attribute of the form tag. For 
clean URLs the value will
+     * be embedded in the URL if possible. Otherwise, it will be added to the 
query string.
+     * 
+     * @param name the parameter name
+     * @param valueOrValues the parameter value(s)
+     * @see ParameterizableTag#addParameter(String, Object)
+     */
+       @Override
+       public void addParameter(String name, Object valueOrValues) {
+        urlBuilder.addParameter(name, valueOrValues);
+    }
+
+    /**
+     * Builds the action attribute, including the context path and any 
parameters.
+     * 
+     * @return the action attribute
+     */
+    protected String buildAction() {
+        String action = urlBuilder.toString();
+        if (action.startsWith("/")) {
+            HttpServletRequest request = (HttpServletRequest) 
getPageContext().getRequest();
+            String contextPath = request.getContextPath();
+
+            if (contextPath != null && !"/".equals(contextPath)
+                    && !action.contains(contextPath + "/")) {
+                action = contextPath + action;
+            }
+        }
+        HttpServletResponse response = (HttpServletResponse) 
getPageContext().getResponse();
+        return response.encodeURL(action);
+    }
 }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to