click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r767682 - in /incubator/click/trunk/click: examples/src/org/apache/click/examples/page/control/SubmitLinkDemo.java examples/webapp/control/submit-link-demo.htm extras/src/org/apache/click/extras/control/SubmitLink.java
Date Wed, 22 Apr 2009 21:45:58 GMT
Author: sabob
Date: Wed Apr 22 21:45:57 2009
New Revision: 767682

URL: http://svn.apache.org/viewvc?rev=767682&view=rev
Log:
added demo and javadoc for custom notification messages

Modified:
    incubator/click/trunk/click/examples/src/org/apache/click/examples/page/control/SubmitLinkDemo.java
    incubator/click/trunk/click/examples/webapp/control/submit-link-demo.htm
    incubator/click/trunk/click/extras/src/org/apache/click/extras/control/SubmitLink.java

Modified: incubator/click/trunk/click/examples/src/org/apache/click/examples/page/control/SubmitLinkDemo.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/page/control/SubmitLinkDemo.java?rev=767682&r1=767681&r2=767682&view=diff
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/page/control/SubmitLinkDemo.java
(original)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/page/control/SubmitLinkDemo.java
Wed Apr 22 21:45:57 2009
@@ -36,21 +36,29 @@
  */
 public class SubmitLinkDemo extends BorderPage {
 
-    /** A submit link. */
-    private SubmitLink submitLink = new SubmitLink("submit");
-
-    /** A submit link which includes parameters. */
-    private SubmitLink paramLink = new SubmitLink("paramLink");
-
-    /** A submit link used outside of a Form control. */
-    private SubmitLink standaloneLink = new SubmitLink("standaloneLink");
-
     public String demo1Msg;
 
     public String demo2Msg;
 
+    public String demo3Msg;
+
+    public String demo4Msg;
+
     public SubmitLinkDemo() {
-        Form form = new Form("form");
+        demo1();
+
+        demo2();
+
+        demo3();
+
+        demo4();
+    }
+
+    public void demo1() {
+        // Create a submit link.
+        final SubmitLink submitLink = new SubmitLink("submit");
+
+        Form form = new Form("demo1");
         addControl(form);
 
         FieldSet fieldSet = new FieldSet("fieldSet");
@@ -61,33 +69,51 @@
         // Add the submit link to the fieldSet
         fieldSet.add(submitLink);
 
-        // Add some parameters to the parameterized submit link
-        paramLink.setValue("myValue");
-        paramLink.setParameter("x", "100");
-
-        // Add the parameterized submit link to the FieldSet
-        fieldSet.add(paramLink);
-
         // The SubmitLink action listener
         submitLink.setActionListener(new ActionListener() {
 
             public boolean onAction(Control source) {
-                demo1Msg = source.getName() + ".onAction invoked at " +
-                    (new Date());
+                demo1Msg = submitLink.getName() + ".onAction invoked at "
+                    + (new Date());
                 return true;
             }
         });
+    }
+
+    public void demo2() {
+        // Create a submit link which includes parameters.
+        final SubmitLink paramLink = new SubmitLink("paramLink");
+
+        Form form = new Form("demo2");
+        addControl(form);
+
+        FieldSet fieldSet = new FieldSet("fieldSet");
+        form.add(fieldSet);
+
+        fieldSet.add(new TextField("name"));
+
+        // Add some parameters to the parameterized submit link
+        paramLink.setValue("myValue");
+        paramLink.setParameter("x", "100");
+
+        // Add the parameterized submit link to the FieldSet
+        fieldSet.add(paramLink);
 
         // The Parameterized SubmitLink action listener
         paramLink.setActionListener(new ActionListener() {
 
             public boolean onAction(Control source) {
-                demo1Msg = source.getName() + ".onAction invoked at " +
-                    (new Date());
-                demo1Msg += "<br>Parameters:" + paramLink.getParameters();
+                demo2Msg = paramLink.getName() + ".onAction invoked at "
+                    + (new Date());
+                demo2Msg += "<br>Parameters:" + paramLink.getParameters();
                 return true;
             }
         });
+    }
+
+    public void demo3() {
+        // Create a standalone submit link.
+        final SubmitLink standaloneLink = new SubmitLink("standaloneLink");
 
         // Add the Standalone SubmitLink to the Page
         addControl(standaloneLink);
@@ -96,10 +122,41 @@
         standaloneLink.setActionListener(new ActionListener() {
 
             public boolean onAction(Control source) {
-                demo2Msg = source.getName() + ".onAction invoked at " +
+                demo3Msg = source.getName() + ".onAction invoked at " +
                     (new Date());
                 return true;
             }
         });
     }
+
+    public void demo4() {
+        // Create a submit link
+        final SubmitLink confirmationLink = new SubmitLink("confirmationLink");
+
+        Form form = new Form("demo4");
+        addControl(form);
+
+        FieldSet fieldSet = new FieldSet("fieldSet");
+        form.add(fieldSet);
+
+        fieldSet.add(new TextField("name"));
+
+        // Add the submit link to the FieldSet
+        fieldSet.add(confirmationLink);
+
+        // Set custom JavaScript for the onclick event. The confirmSubmit function
+        // is defined in the page template -> submit-link-demo.htm
+        String clickEvent = "return confirmSubmit(this, '" + form.getName() + "', 'Are you
sure?');";
+        confirmationLink.setOnClick(clickEvent);
+
+        // The Parameterized SubmitLink action listener
+        confirmationLink.setActionListener(new ActionListener() {
+
+            public boolean onAction(Control source) {
+                demo4Msg = confirmationLink.getName() + ".onAction invoked at "
+                    + (new Date());
+                return true;
+            }
+        });
+    }
 }

Modified: incubator/click/trunk/click/examples/webapp/control/submit-link-demo.htm
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/webapp/control/submit-link-demo.htm?rev=767682&r1=767681&r2=767682&view=diff
==============================================================================
--- incubator/click/trunk/click/examples/webapp/control/submit-link-demo.htm (original)
+++ incubator/click/trunk/click/examples/webapp/control/submit-link-demo.htm Wed Apr 22 21:45:57
2009
@@ -17,13 +17,14 @@
    under the License.*#
 -->
 
+This page demonstrates some usage patterns of the SubmitLink control.
+
 <h3>Demo1</h3>
 
 In this first demo is shown how the Form is submitted when the SubmitLink is
-clicked. Note that the SubmitLink parameters will be sent as part of the Form
-submission.
+clicked.
 
-$form
+$demo1
 
 #if ($demo1Msg)
 <p class="infoMsg"> $demo1Msg</p>
@@ -31,16 +32,48 @@
 
 <h3>Demo2</h3>
 
-This demo shows how the SubmitLink can be used outside a Form. When a SubmitLink
+In this second demo is shown how the SubmitLink's parameters are
+submitted together with the Form.
+
+$demo2
+
+#if ($demo2Msg)
+<p class="infoMsg"> $demo2Msg</p>
+#end
+
+<h3>Demo3</h3>
+
+This demo shows how the SubmitLink can be used outside of a Form. When a SubmitLink
 is not inside a Form it behaves like a normal ActionLink.
 
 <p/>
 
-Click <a href="$standaloneLink.href">here</a> to invoke the SubmitLink.
+Click $standaloneLink to demonstrate.
 
-#if ($demo2Msg)
-<p class="infoMsg"> $demo2Msg</p>
+#if ($demo3Msg)
+<p class="infoMsg"> $demo3Msg</p>
 #end
 
+<h3>Demo4</h3>
+
+<script type="text/javascript">
+    function confirmSubmit(link, formName, msg) {
+        var confirm = window.confirm(msg);
+        if (confirm) {
+            return Click.submitLinkAction(link, formName);
+        } else {
+            return false;
+        }
+    }
+</script>
+
+This demo shows how a confirmation message can be displayed before the
+SubmitLink submits the Form.
 
-$dForm
\ No newline at end of file
+<p/>
+
+$demo4
+
+#if ($demo4Msg)
+<p class="infoMsg"> $demo4Msg</p>
+#end

Modified: incubator/click/trunk/click/extras/src/org/apache/click/extras/control/SubmitLink.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/extras/src/org/apache/click/extras/control/SubmitLink.java?rev=767682&r1=767681&r2=767682&view=diff
==============================================================================
--- incubator/click/trunk/click/extras/src/org/apache/click/extras/control/SubmitLink.java
(original)
+++ incubator/click/trunk/click/extras/src/org/apache/click/extras/control/SubmitLink.java
Wed Apr 22 21:45:57 2009
@@ -42,7 +42,8 @@
  * <b>Please note:</b> SubmitLink uses a <tt>JavaScript</tt> function
to submit
  * the Form. This JavaScript function also creates <tt>hidden fields</tt>
  * for each SubmitLink parameter, to ensure the link's parameters are
- * submitted.
+ * submitted. See {@link #getSubmitScript(java.lang.String)} for more details on
+ * the JavaScript used to submit the Form.
  * <p/>
  * <b>Also note:</b> if SubmitLink is <tt>not</tt> added to a Form,
it behaves
  * like an {@link org.apache.click.control.ActionLink ActionLink} control.
@@ -63,6 +64,34 @@
  *     }
  * } </pre>
  *
+ * <h3>Custom Popup Message</h3>
+ *
+ * The SubmitLink uses the <tt>"onclick"</tt> event handler to submit the Form.
+ * <p/>
+ * If you would like to customize the <tt>"onclick"</tt> event handler, for
+ * example to show a confirmation popup message, you can retrieve the link's
+ * submit script through the {@link #getSubmitScript(java.lang.String)} method.
+ * <p/>
+ * Here is an example of providing a confirmation popup message before submitting
+ * the Form:
+ *
+ * <pre class="prettyprint">
+ * public MyPage extends Page {
+ *
+ *     public void onInit() {
+ *         Form form = new Form("form");
+ *         SubmitLink link = new SubmitLink("link", "Delete");
+ *         form.add(link);
+ *
+ *         // Get the submit script for the given form name
+ *         String submitScript = submitLink.getSubmitScript(form.getName());
+ *
+ *         // Add a confirmation popup message
+ *         scriptLink.setOnClick("var confirm = window.confirm('Are you sure?'); if (confirm)
"
+ *             + submitScript + " else return false;");
+ *     }
+ * } </pre>
+ *
  * <h3>JavaScript and CSS Dependencies</h3>
  *
  * When SubmitLink is added to a Form it will include the following resources:
@@ -334,6 +363,36 @@
         return getForm() != null;
     }
 
+    /**
+     * Return the JavaScript that submits the Form with the given formName.
+     * <p/>
+     * The script returned by this method is:
+     *
+     * <pre class="prettyprint">
+     * "return Click.submitLinkAction(this, 'formName');" </pre>
+     *
+     * The <tt>Click.submitLinkAction</tt> function takes as parameters a reference
+     * to the SubmitLink and the name of the Form to submit. (The
+     * Click.submitLinkAction is defined in <tt>/click/extras-control.js</tt>)
+     *
+     * @param formName the name of the Form to submit
+     *
+     * @return the JavaScript that submits the Form with the given formName
+     *
+     * @throws IllegalStateException if the form name is null
+     */
+    public String getSubmitScript(String formName) {
+        if (formName == null) {
+            throw new IllegalStateException("formName cannot be null.");
+        }
+
+        HtmlStringBuffer buffer = new HtmlStringBuffer(60);
+        buffer.append("return Click.submitLinkAction(this, '");
+        buffer.append(formName);
+        buffer.append("');");
+        return buffer.toString();
+    }
+
     // --------------------------------------------------------- Public Methods
 
     /**
@@ -472,7 +531,7 @@
         // has not been set
         Form form = getForm();
         if (form != null && getOnClick() == null) {
-            setOnClick("return Click.submitLinkAction(this, '" + form.getName() + "');");
+            setOnClick(getSubmitScript(form.getName()));
         }
 
         super.render(buffer);



Mime
View raw message