click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r978834 - in /click/trunk/click/framework/src/org/apache/click/control: AbstractLink.java ActionButton.java ActionLink.java
Date Sat, 24 Jul 2010 09:21:35 GMT
Author: sabob
Date: Sat Jul 24 09:21:33 2010
New Revision: 978834

URL: http://svn.apache.org/viewvc?rev=978834&view=rev
Log:
without stateful pages we can revert CLK-685

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

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=978834&r1=978833&r2=978834&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 Sat Jul 24
09:21:33 2010
@@ -270,9 +270,6 @@ public abstract class AbstractLink exten
      * 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
      */
@@ -339,9 +336,6 @@ 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
      */
@@ -386,9 +380,6 @@ 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() {
@@ -399,6 +390,42 @@ public abstract class AbstractLink exten
     }
 
     /**
+     * Set the AbstractLink parameter map.
+     *
+     * @param parameters the link parameter map
+     */
+    public void setParameters(Map parameters) {
+        this.parameters = parameters;
+    }
+
+    /**
+     * Defines a link parameter that will have its value bound to a matching
+     * request parameter. {@link #setParameter(java.lang.String, java.lang.Object) setParameter}
+     * implicitly defines a parameter as well.
+     * <p/>
+     * <b>Please note:</b> parameters need only be defined for Ajax requests.
+     * For non-Ajax requests, <tt>all</tt> incoming request parameters
+     * are bound, whether they are defined or not. This behavior may change in a
+     * future release.
+     * <p/>
+     * <b>Also note:</b> link parameters are bound to request parameters
+     * during the {@link #onProcess()} event, so link parameters must be defined
+     * in the Page constructor or <tt>onInit()</tt> event.
+     *
+     * @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> localParameters = getParameters();
+        if (!localParameters.containsKey(name)) {
+            localParameters.put(name, null);
+        }
+    }
+
+    /**
      * Return true if the AbstractLink has parameters, false otherwise.
      *
      * @return true if the AbstractLink has parameters, false otherwise
@@ -504,9 +531,9 @@ public abstract class AbstractLink exten
         if (id != null) {
             return context.getRequestParameter(id) != null;
         } else {
-            String name = getName();
-            if (name != null) {
-                return name.equals(context.getRequestParameter(ActionLink.ACTION_LINK));
+            String localName = getName();
+            if (localName != null) {
+                return localName.equals(context.getRequestParameter(ActionLink.ACTION_LINK));
             }
         }
         return false;
@@ -677,17 +704,15 @@ public abstract class AbstractLink exten
     /**
      * 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
+     * <p/>
+     * For non-Ajax requests this method will bind <tt>all</tt> incoming request
+     * parameters to the link. For Ajax requests this method will only bind
+     * the parameters already defined on the link.
      *
      * @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;
@@ -700,10 +725,12 @@ public abstract class AbstractLink exten
 
         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
+            // Do not process request parameters that return null values. Null
+            // values are only returned if the request parameter is not present.
+            // A null value can only occur for Ajax requests which processes
+            // parameters defined on the link, not the incoming parameters.
+            // The reason for not processing the null value is because it would
+            // nullify parametesr that was set during onInit
             if (values == null) {
                 continue;
             }

Modified: click/trunk/click/framework/src/org/apache/click/control/ActionButton.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/ActionButton.java?rev=978834&r1=978833&r2=978834&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/ActionButton.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/ActionButton.java Sat Jul 24
09:21:33 2010
@@ -304,9 +304,6 @@ public class ActionButton extends Button
      * Return the button 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 button request parameter value
      */
@@ -341,9 +338,6 @@ public class ActionButton extends Button
     /**
      * Return the ActionButton parameters Map.
      *
-     * @deprecated use {@link org.apache.click.Context#getRequestParameter(java.lang.String)}
-     * instead
-     *
      * @return the ActionButton parameters Map
      */
     public Map<String, Object> getParameters() {
@@ -354,6 +348,42 @@ public class ActionButton extends Button
     }
 
     /**
+     * Set the ActionButton parameter map.
+     *
+     * @param parameters the button parameter map
+     */
+    public void setParameters(Map parameters) {
+        this.parameters = parameters;
+    }
+
+    /**
+     * Defines a button parameter that will have its value bound to a matching
+     * request parameter. {@link #setParameter(java.lang.String, java.lang.Object) setParameter}
+     * implicitly defines a parameter as well.
+     * <p/>
+     * <b>Please note:</b> parameters need only be defined for Ajax requests.
+     * For non-Ajax requests, <tt>all</tt> incoming request parameters
+     * are bound, whether they are defined or not. This behavior may change in a
+     * future release.
+     * <p/>
+     * <b>Also note:</b> button parameters are bound to request parameters
+     * during the {@link #onProcess()} event, so button parameters must be defined
+     * in the Page constructor or <tt>onInit()</tt> event.
+     *
+     * @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> localParameters = getParameters();
+        if (!localParameters.containsKey(name)) {
+            localParameters.put(name, null);
+        }
+    }
+
+    /**
      * Return true if the ActionButton has parameters or false otherwise.
      *
      * @return true if the ActionButton has parameters on false otherwise
@@ -487,12 +517,10 @@ public class ActionButton extends Button
         clicked = getName().equals(context.getRequestParameter(ACTION_BUTTON));
 
         if (clicked) {
-            String value = context.getRequestParameter(VALUE);
-            if (value != null) {
-                setValue(value);
+            String localValue = context.getRequestParameter(VALUE);
+            if (localValue != null) {
+                setValue(localValue);
             }
-            // TODO refactor link not to bind parameters since it can lead to
-            // memory leaks, especially when using Ajax. Remove the line below
             bindRequestParameters(context);
         }
     }
@@ -567,17 +595,15 @@ public class ActionButton extends Button
     /**
      * This method binds the submitted request parameters to the buttons
      * parameters.
-     *
-     * @deprecated binding button parameters can cause memory leaks, use
-     * {@link org.apache.click.Context#getRequestParameter(java.lang.String)}
-     * instead
+     * <p/>
+     * For non-Ajax requests this method will bind <tt>all</tt> incoming request
+     * parameters to the link. For Ajax requests this method will only bind
+     * the parameters already defined on the link.
      *
      * @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;
@@ -590,10 +616,12 @@ public class ActionButton extends Button
 
         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
+            // Do not process request parameters that return null values. Null
+            // values are only returned if the request parameter is not present.
+            // A null value can only occur for Ajax requests which processes
+            // parameters defined on the button, not the incoming parameters.
+            // The reason for not processing the null value is because it would
+            // nullify parametesr that was set during onInit
             if (values == null) {
                 continue;
             }

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=978834&r1=978833&r2=978834&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 Sat Jul 24 09:21:33
2010
@@ -490,8 +490,6 @@ public class ActionLink extends Abstract
             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);
         }
     }



Mime
View raw message