Return-Path: Delivered-To: apmail-incubator-click-commits-archive@minotaur.apache.org Received: (qmail 40588 invoked from network); 24 Jul 2009 22:08:32 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 24 Jul 2009 22:08:32 -0000 Received: (qmail 33505 invoked by uid 500); 24 Jul 2009 22:09:38 -0000 Delivered-To: apmail-incubator-click-commits-archive@incubator.apache.org Received: (qmail 33486 invoked by uid 500); 24 Jul 2009 22:09:38 -0000 Mailing-List: contact click-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: click-dev@incubator.apache.org Delivered-To: mailing list click-commits@incubator.apache.org Received: (qmail 33476 invoked by uid 99); 24 Jul 2009 22:09:38 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Jul 2009 22:09:38 +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; Fri, 24 Jul 2009 22:09:27 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 6F27A238889B; Fri, 24 Jul 2009 22:09:06 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r797669 - in /incubator/click/trunk/click: documentation/docs/faq.html framework/src/org/apache/click/control/Form.java Date: Fri, 24 Jul 2009 22:09:06 -0000 To: click-commits@incubator.apache.org From: sabob@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090724220906.6F27A238889B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sabob Date: Fri Jul 24 22:09:05 2009 New Revision: 797669 URL: http://svn.apache.org/viewvc?rev=797669&view=rev Log: added docs about resubmitting form by click submit button twice in quick succession Modified: incubator/click/trunk/click/documentation/docs/faq.html incubator/click/trunk/click/framework/src/org/apache/click/control/Form.java Modified: incubator/click/trunk/click/documentation/docs/faq.html URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/documentation/docs/faq.html?rev=797669&r1=797668&r2=797669&view=diff ============================================================================== --- incubator/click/trunk/click/documentation/docs/faq.html (original) +++ incubator/click/trunk/click/documentation/docs/faq.html Fri Jul 24 22:09:05 2009 @@ -430,24 +430,48 @@
12.  How can you prevent multiple form posts?
You can prevent multiple form posts by using the Post Redirect pattern. With - this pattern once the user has posted a form you redirect to another page. - If the user then presses the refresh button, they will making a GET request on the - current page. + this pattern once the user has posted a form you redirect to another page. + If the user then presses the refresh button, they will be making a GET request + on the current page. +
+public class Purchase extends Page {
+    ..
+
+    public boolean onPurchase() {
+        if (form.isValid()) {
+            Order order = new Order();
+            form.copyTo(order);
+            getOrderService().save(order);
+
+            // Perform a redirect after post to protect against users pressing
+            // the refresh or back button
+            setRedirect(Purchase.class);
+            return false;
+        }
+        return true;
+    }
+} 

Please see the Redirect After Post article for more information on this topic.

- To prevent users resubmitting a form with the browser back button use the - Form + Another common way duplicate posts occur is if the user accidentally + click the Form's submit button twice, in quick succession. Redirecting to another + won't protect against the second accidental submit. +

+ Click provides a clean way to prevent users from resubmitting the same Form + through the Form's onSubmitCheck() method: -

-public class Purchase extends Page {
+
+public class Purchase extends Page {
     ..
     
-    public boolean onSecurityCheck() {
-        return form.onSubmitCheck(this, "/invalid-submit.html");
+    public boolean onSecurityCheck() {
+        // Placing the onSubmitCheck in the onSecurityCheck event, prevents the
+        // page from being processed if a Form is resubmitted a second time
+        return form.onSubmitCheck(this, "/invalid-submit.html");
     }
 } 

Modified: incubator/click/trunk/click/framework/src/org/apache/click/control/Form.java URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/org/apache/click/control/Form.java?rev=797669&r1=797668&r2=797669&view=diff ============================================================================== --- incubator/click/trunk/click/framework/src/org/apache/click/control/Form.java (original) +++ incubator/click/trunk/click/framework/src/org/apache/click/control/Form.java Fri Jul 24 22:09:05 2009 @@ -1848,8 +1848,9 @@ /** * Perform a form submission check ensuring the user has not replayed the - * form submission by using the browser back button. If the form submit - * is valid this method will return true, otherwise set the page to + * form submission by using the browser's back or refresh buttons or by + * clicking the Form submit button twice, in quick succession. If the form + * submit is valid this method will return true, otherwise set the page to * redirect to the given redirectPath and return false. *

* This method will add a token to the user's session and a hidden field @@ -1858,12 +1859,12 @@ * Form submit checks should be performed before the pages controls are * processed in the Page onSecurityCheck method. For example: * - *

-     * public class Order extends Page {
+     * 
+     * public class Order extends Page {
      *     ..
      *
-     *     public boolean onSecurityCheck() {
-     *         return form.onSubmitCheck(this, "/invalid-submit.html");
+     *     public boolean onSecurityCheck() {
+     *         return form.onSubmitCheck(this, "/invalid-submit.html");
      *     }
      * } 
*