click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From med...@apache.org
Subject svn commit: r775919 - /incubator/click/trunk/click/framework/src/org/apache/click/Page.java
Date Mon, 18 May 2009 12:30:24 GMT
Author: medgar
Date: Mon May 18 12:30:24 2009
New Revision: 775919

URL: http://svn.apache.org/viewvc?rev=775919&view=rev
Log:
CLK-536

Modified:
    incubator/click/trunk/click/framework/src/org/apache/click/Page.java

Modified: incubator/click/trunk/click/framework/src/org/apache/click/Page.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/org/apache/click/Page.java?rev=775919&r1=775918&r2=775919&view=diff
==============================================================================
--- incubator/click/trunk/click/framework/src/org/apache/click/Page.java (original)
+++ incubator/click/trunk/click/framework/src/org/apache/click/Page.java Mon May 18 12:30:24
2009
@@ -21,10 +21,12 @@
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.click.util.Format;
+import org.apache.click.util.HtmlStringBuffer;
 import org.apache.click.util.MessagesMap;
 import org.apache.click.util.PageImports;
 import org.apache.commons.lang.StringUtils;
@@ -1095,6 +1097,23 @@
      * @param location the path to redirect the request to
      */
     public void setRedirect(String location) {
+        setRedirect(location, null);
+    }
+
+    /**
+     * Set the request to redirect to the give page class.
+     *
+     * @see #setRedirect(java.lang.String)
+     *
+     * @param pageClass the class of the Page to redirect the request to
+     * @throws IllegalArgumentException if the Page Class is not configured
+     * with a unique path
+     */
+    public void setRedirect(Class pageClass) {
+        setRedirect(pageClass, null);
+    }
+
+    public void setRedirect(String location, Map params){
         if (StringUtils.isNotBlank(location)) {
             if (location.charAt(0) == '/') {
                 Context context = getContext();
@@ -1106,19 +1125,30 @@
                 }
             }
         }
+
+        if (params != null && !params.isEmpty()) {
+            HtmlStringBuffer buffer = new HtmlStringBuffer();
+
+            for (Iterator i = params.keySet().iterator(); i.hasNext();) {
+                String paramName = i.next().toString();
+                Object paramValue = params.get(paramName);
+                if (paramValue != null) {
+                    buffer.append("&");
+                    buffer.append(paramName);
+                    buffer.append("=");
+                    buffer.append(paramValue);
+                }
+            }
+
+            if (buffer.length() > 0) {
+                location += "?" + buffer.toString();
+            }
+        }
+
         redirect = location;
     }
 
-    /**
-     * Set the request to redirect to the give page class.
-     *
-     * @see #setRedirect(java.lang.String)
-     *
-     * @param pageClass the class of the Page to redirect the request to
-     * @throws IllegalArgumentException if the Page Class is not configured
-     * with a unique path
-     */
-    public void setRedirect(Class pageClass) {
+    public void setRedirect(Class pageClass, Map params) {
         String target = getContext().getPagePath(pageClass);
 
         // If page class maps to a jsp, convert to htm which allows ClickServlet
@@ -1126,7 +1156,8 @@
         if (target != null && target.endsWith(".jsp")) {
             target = StringUtils.replaceOnce(target, ".jsp", ".htm");
         }
-        setRedirect(target);
+
+        setRedirect(target, params);
     }
 
     /**



Mime
View raw message