Return-Path: Delivered-To: apmail-click-commits-archive@www.apache.org Received: (qmail 67596 invoked from network); 8 Jun 2010 11:07:15 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 8 Jun 2010 11:07:15 -0000 Received: (qmail 88877 invoked by uid 500); 8 Jun 2010 11:07:14 -0000 Delivered-To: apmail-click-commits-archive@click.apache.org Received: (qmail 88857 invoked by uid 500); 8 Jun 2010 11:07:14 -0000 Mailing-List: contact commits-help@click.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: click-dev@click.apache.org Delivered-To: mailing list commits@click.apache.org Received: (qmail 88849 invoked by uid 99); 8 Jun 2010 11:07:13 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Jun 2010 11:07:13 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Jun 2010 11:07:11 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id AD63923889BF; Tue, 8 Jun 2010 11:06:49 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r952604 - in /click/trunk/click/framework/src/org/apache/click/control: AbstractLink.java ActionLink.java Date: Tue, 08 Jun 2010 11:06:49 -0000 To: commits@click.apache.org From: sabob@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100608110649.AD63923889BF@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sabob Date: Tue Jun 8 11:06:49 2010 New Revision: 952604 URL: http://svn.apache.org/viewvc?rev=952604&view=rev Log: added strict parameter binding option. CLK-685 Modified: 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/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=952604&r1=952603&r2=952604&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 Tue Jun 8 11:06:49 2010 @@ -18,10 +18,10 @@ */ package org.apache.click.control; -import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import java.util.Set; import javax.servlet.http.HttpServletRequest; import org.apache.click.Context; @@ -74,6 +74,14 @@ 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 ----------------------------------------------------------- /** @@ -267,6 +275,77 @@ 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. + *

+ * Strict parameter binding means that incoming request parameters are only + * added to the link {@link #parameters parameter map} if these parameters + * have been defined before the {@link #onProcess()} event. + *

+ * 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)}. + *

+ * For example: + *

+     * private ActionLink link = new ActionLink("link");
+     *
+     * public void onInit() {
+     *     link.defineParameter("id"); // Explicitly defined parameter
+     *     link.setParameter("customerName", "John"); // Implicitly defined parameter
+     * } 
+ * + * @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. + *

+ * Please note: by default parameters only need to be defined for + * ajax requests. For non-ajax requests, all incoming request parameters + * are bound. This behavior can be controlled through the + * {@link #setStrictParameterBinding(boolean) strictParameterBinding} + * property. + *

+ * Also note: parameters must be defined before 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 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. * @@ -660,10 +739,24 @@ public abstract class AbstractLink exten @SuppressWarnings("unchecked") protected void bindRequestParameters(Context context) { HttpServletRequest request = context.getRequest(); - Enumeration paramNames = request.getParameterNames(); - while (paramNames.hasMoreElements()) { - String param = paramNames.nextElement().toString(); + Set parameterNames = null; + + if (strictParameterBinding == null) { + if (getContext().isAjaxRequest()) { + parameterNames = getParameters().keySet(); + } else { + parameterNames = request.getParameterMap().keySet(); + } + } else { + if (isStrictParameterBinding()) { + parameterNames = getParameters().keySet(); + } else { + parameterNames = request.getParameterMap().keySet(); + } + } + + for (String param : parameterNames) { String[] values = request.getParameterValues(param); if (values != null && values.length == 1) { 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=952604&r1=952603&r2=952604&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 Tue Jun 8 11:06:49 2010 @@ -510,4 +510,17 @@ 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); + } }