click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r959310 - in /click/trunk/click: extras/src/org/apache/click/extras/control/SubmitLink.java framework/src/org/apache/click/control/AbstractLink.java framework/src/org/apache/click/control/ActionLink.java
Date Wed, 30 Jun 2010 13:52:56 GMT
Author: sabob
Date: Wed Jun 30 13:52:56 2010
New Revision: 959310

URL: http://svn.apache.org/viewvc?rev=959310&view=rev
Log:
removed strictParameterBinding property. Deprecated getParameterXXX instead.

Modified:
    click/trunk/click/extras/src/org/apache/click/extras/control/SubmitLink.java
    click/trunk/click/framework/src/org/apache/click/control/AbstractLink.java
    click/trunk/click/framework/src/org/apache/click/control/ActionLink.java

Modified: click/trunk/click/extras/src/org/apache/click/extras/control/SubmitLink.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/control/SubmitLink.java?rev=959310&r1=959309&r2=959310&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/control/SubmitLink.java (original)
+++ click/trunk/click/extras/src/org/apache/click/extras/control/SubmitLink.java Wed Jun 30
13:52:56 2010
@@ -18,9 +18,9 @@
  */
 package org.apache.click.extras.control;
 
-import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 import javax.servlet.http.HttpServletRequest;
 import org.apache.click.Context;
 import org.apache.click.control.ActionLink;
@@ -271,6 +271,9 @@ public class SubmitLink extends ActionLi
     /**
      * Set the parameter prefix that is applied to the SubmitLink parameters.
      *
+     * @deprecated the link request parameter binding will be removed in a future
+     * release, thus removing the need for parameter prefixing
+     *
      * @param prefix the parameter prefix
      */
     public void setParameterPrefix(String prefix) {
@@ -280,6 +283,9 @@ public class SubmitLink extends ActionLi
     /**
      * Return the parameter prefix that is applied to the SubmitLink parameters.
      *
+     * @deprecated the link request parameter binding will be removed in a future
+     * release, thus removing the need for parameter prefixing
+     *
      * @return the parameter prefix that is applied to the SubmitLink parameters.
      */
     public String getParameterPrefix() {
@@ -411,14 +417,26 @@ public class SubmitLink extends ActionLi
             // SubmitLink parameters are prefixed when included inside a Form
             String prefix = getParameterPrefix();
 
+            // TODO: create a VALUE for SubmitLink with a static prefix in order
+            // to obscure the parameter from Form fields
+            /*
+            String value = context.getRequestParameter(prefix + VALUE);
+            if (value != null) {
+                setValue(value);
+            }*/
+
+            // TODO refactor link not to bind parameters since it can lead to
+            // memory leaks, especially when using Ajax. Remove the code below
             HttpServletRequest request = context.getRequest();
-            Enumeration paramNames = request.getParameterNames();
+            Set<String> parameterNames = request.getParameterMap().keySet();
 
             boolean hasParentForm = hasParentForm();
 
-            while (paramNames.hasMoreElements()) {
-                String param = paramNames.nextElement().toString();
+            for (String param : parameterNames) {
                 String[] values = request.getParameterValues(param);
+                if (values == null) {
+                    continue;
+                }
 
                 if (hasParentForm) {
                     // Only bind parameters that start with the prefix
@@ -426,7 +444,7 @@ public class SubmitLink extends ActionLi
 
                         // Remove prefix from parameters
                         String key = param.substring(prefix.length());
-                        if (values != null && values.length == 1) {
+                        if (values.length == 1) {
                             getParameters().put(key, values[0]);
                         } else {
                             getParameters().put(key, values);
@@ -434,7 +452,7 @@ public class SubmitLink extends ActionLi
                     }
 
                 } else {
-                    if (values != null && values.length == 1) {
+                    if (values.length == 1) {
                         getParameters().put(param, values[0]);
                     } else {
                         getParameters().put(param, values);

Modified: click/trunk/click/framework/src/org/apache/click/control/AbstractLink.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/AbstractLink.java?rev=959310&r1=959309&r2=959310&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/AbstractLink.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/AbstractLink.java Wed Jun 30
13:52:56 2010
@@ -74,14 +74,6 @@ public abstract class AbstractLink exten
     /** Flag to set if both icon and text are rendered, default value is false. */
     protected boolean renderLabelAndImage = false;
 
-    /**
-     * Flag indicating whether incoming request parameters are only bound to the
-     * link {@link #parameters} if they have been defined before the
-     * {@link #onProcess()} event. Strict parameter binding will be applied for
-     * ajax requests, while non-strict binding is used for non-ajax requests.
-     */
-    protected Boolean strictParameterBinding = null;
-
     // Constructors -----------------------------------------------------------
 
     /**
@@ -275,80 +267,12 @@ public abstract class AbstractLink exten
     }
 
     /**
-     * Return true if strict parameter binding is used, false otherwise.
-     *
-     * @see {@link #setStrictParameterBinding(boolean)} for more information
-     *
-     * @return true if strict parameter binding is used, false otherwise
-     */
-    public boolean isStrictParameterBinding() {
-        if (strictParameterBinding == null) {
-            return Boolean.FALSE;
-        }
-        return strictParameterBinding;
-    }
-
-    /**
-     * Set whether strict parameter binding should be used. By default strict
-     * parameter binding is used for ajax requests, while non-strict binding is
-     * used for non-ajax requests.
-     * <p/>
-     * Strict parameter binding means that incoming request parameters are only
-     * added to the link {@link #parameters parameter map} if these parameters
-     * have been defined <i>before</i> the {@link #onProcess()} event.
-     * <p/>
-     * A link parameter is automatically defined when
-     * {@link #setParameter(java.lang.String, java.lang.String) setting a parameter}.
-     * Alternatively a parameter can be explicitly defined via
-     * {@link #defineParameter(java.lang.String)}.
-     * <p/>
-     * For example:
-     * <pre class="prettyprint">
-     * private ActionLink link = new ActionLink("link");
-     *
-     * public void onInit() {
-     *     link.defineParameter("id"); // Explicitly defined parameter
-     *     link.setParameter("customerName", "John"); // Implicitly defined parameter
-     * } </pre>
-     *
-     * @param value true if strict parameter binding should be used, false
-     * otherwise
-     */
-    public void setStrictParameterBinding(boolean value) {
-        this.strictParameterBinding = value;
-    }
-
-    /**
-     * Defines a link parameter that will be bound to its matching request
-     * parameter.
-     * <p/>
-     * <b>Please note:</b> by default parameters only need to be defined for
-     * ajax requests. For non-ajax requests, <i>all</i> incoming request parameters
-     * are bound. This behavior can be controlled through the
-     * {@link #setStrictParameterBinding(boolean) strictParameterBinding}
-     * property.
-     * <p/>
-     * <b>Also note:</b> parameters must be defined <i>before</i>
the
-     * {@link #onProcess()} event, otherwise they will not be bound to
-     * incoming request parameters.
-     *
-     * @param name the name of the parameter to define
-     */
-    public void defineParameter(String name) {
-        if (name == null) {
-            throw new IllegalArgumentException("Null name parameter");
-        }
-
-        Map<String, Object> parameters = getParameters();
-        if (!parameters.containsKey(name)) {
-            parameters.put(name, null);
-        }
-    }
-
-    /**
      * Return the link request parameter value for the given name, or null if
      * the parameter value does not exist.
      *
+     * @deprecated use {@link org.apache.click.Context#getRequestParameter(java.lang.String)}
+     * instead
+     *
      * @param name the name of request parameter
      * @return the link request parameter value
      */
@@ -415,6 +339,9 @@ public abstract class AbstractLink exten
      * Return the link request parameter values for the given name, or null if
      * the parameter values does not exist.
      *
+     * @deprecated use {@link org.apache.click.Context#getRequestParameterValues(java.lang.String)}
+     * instead
+     *
      * @param name the name of request parameter
      * @return the link request parameter values
      */
@@ -459,6 +386,9 @@ public abstract class AbstractLink exten
     /**
      * Return the AbstractLink parameters Map.
      *
+     * @deprecated use {@link org.apache.click.Context#getRequestParameter(java.lang.String)}
+     * instead
+     *
      * @return the AbstractLink parameters Map
      */
     public Map<String, Object> getParameters() {
@@ -745,35 +675,40 @@ public abstract class AbstractLink exten
     }
 
     /**
-     * This method binds the submitted request parameters to the link's
+     * This method binds the submitted request parameters to the link
      * parameters.
      *
+     * @deprecated binding link parameters can cause memory leaks, use
+     * {@link org.apache.click.Context#getRequestParameter(java.lang.String)}
+     * instead
+     *
      * @param context the request context
      */
     @SuppressWarnings("unchecked")
     protected void bindRequestParameters(Context context) {
+        // TODO: remove this method in a future release since it can lead to
+        // memory leaks
         HttpServletRequest request = context.getRequest();
 
         Set<String> parameterNames = null;
 
-        if (strictParameterBinding == null) {
-            if (getContext().isAjaxRequest()) {
-                parameterNames = getParameters().keySet();
-            } else {
-                parameterNames = request.getParameterMap().keySet();
-            }
+        if (context.isAjaxRequest()) {
+            parameterNames = getParameters().keySet();
         } else {
-            if (isStrictParameterBinding()) {
-                parameterNames = getParameters().keySet();
-            } else {
-                parameterNames = request.getParameterMap().keySet();
-            }
+            parameterNames = request.getParameterMap().keySet();
         }
 
         for (String param : parameterNames) {
             String[] values = request.getParameterValues(param);
+            // Do not process parameters that are not defined as it would nullify
+            // parameters that was explicitly set during Page.onInit. This only
+            // occurs for Ajax requests which processes all parameters defined
+            // on the link
+            if (values == null) {
+                continue;
+            }
 
-            if (values != null && values.length == 1) {
+            if (values.length == 1) {
                 getParameters().put(param, values[0]);
             } else {
                 getParameters().put(param, values);

Modified: click/trunk/click/framework/src/org/apache/click/control/ActionLink.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/ActionLink.java?rev=959310&r1=959309&r2=959310&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/ActionLink.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/ActionLink.java Wed Jun 30 13:52:56
2010
@@ -18,6 +18,8 @@
  */
 package org.apache.click.control;
 
+import java.util.Set;
+import javax.servlet.http.HttpServletRequest;
 import org.apache.click.Context;
 import org.apache.click.util.ClickUtils;
 import org.apache.click.util.HtmlStringBuffer;
@@ -485,6 +487,12 @@ public class ActionLink extends Abstract
         clicked = getName().equals(context.getRequestParameter(ACTION_LINK));
 
         if (clicked) {
+            String value = context.getRequestParameter(VALUE);
+            if (value != null) {
+                setValue(value);
+            }
+            // TODO refactor link not to bind parameters since it can lead to
+            // memory leaks, especially when using Ajax. Remove the line below
             bindRequestParameters(context);
         }
     }
@@ -509,18 +517,4 @@ public class ActionLink extends Abstract
         }
         return true;
     }
-
-    // Protected Methods ------------------------------------------------------
-
-    /**
-     * This method binds the submitted request parameters to the link's
-     * parameters.
-     *
-     * @param context the request context
-     */
-    @Override
-    protected void bindRequestParameters(Context context) {
-        defineParameter(VALUE);
-        super.bindRequestParameters(context);
-    }
 }



Mime
View raw message