click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r962888 - in /click/trunk/click/examples: src/org/apache/click/examples/page/ajax/accordion/ src/org/apache/click/examples/page/ajax/content/ webapp/WEB-INF/ webapp/ajax/ webapp/ajax/accordion/ webapp/ajax/compare/ webapp/ajax/content/ weba...
Date Sat, 10 Jul 2010 17:17:58 GMT
Author: sabob
Date: Sat Jul 10 17:17:57 2010
New Revision: 962888

URL: http://svn.apache.org/viewvc?rev=962888&view=rev
Log:
added xml and json demos

Added:
    click/trunk/click/examples/src/org/apache/click/examples/page/ajax/accordion/AccordionPage.java
      - copied, changed from r962426, click/trunk/click/examples/src/org/apache/click/examples/page/ajax/accordion/AjaxAccordion.java
    click/trunk/click/examples/src/org/apache/click/examples/page/ajax/content/
    click/trunk/click/examples/src/org/apache/click/examples/page/ajax/content/JsonResponsePage.java
    click/trunk/click/examples/src/org/apache/click/examples/page/ajax/content/XmlResponsePage.java
    click/trunk/click/examples/webapp/ajax/accordion/accordion.htm
      - copied unchanged from r962419, click/trunk/click/examples/webapp/ajax/accordion/ajax-accordion.htm
    click/trunk/click/examples/webapp/ajax/accordion/accordion.js
      - copied, changed from r962419, click/trunk/click/examples/webapp/ajax/accordion/ajax-accordion.js
    click/trunk/click/examples/webapp/ajax/content/
    click/trunk/click/examples/webapp/ajax/content/json-response.htm
    click/trunk/click/examples/webapp/ajax/content/xml-response.htm
Removed:
    click/trunk/click/examples/src/org/apache/click/examples/page/ajax/accordion/AjaxAccordion.java
    click/trunk/click/examples/webapp/ajax/accordion/ajax-accordion.htm
    click/trunk/click/examples/webapp/ajax/accordion/ajax-accordion.js
Modified:
    click/trunk/click/examples/webapp/WEB-INF/menu.xml
    click/trunk/click/examples/webapp/ajax/ajax-behavior.htm
    click/trunk/click/examples/webapp/ajax/compare/jquery-ajax-demo.htm
    click/trunk/click/examples/webapp/ajax/compare/prototype-ajax-demo.htm
    click/trunk/click/examples/webapp/ajax/form/advanced-form-ajax.js
    click/trunk/click/examples/webapp/ajax/form/simple-form-ajax.js
    click/trunk/click/examples/webapp/ajax/page-action.htm
    click/trunk/click/examples/webapp/ajax/table/table-ajax-demo.js

Copied: click/trunk/click/examples/src/org/apache/click/examples/page/ajax/accordion/AccordionPage.java
(from r962426, click/trunk/click/examples/src/org/apache/click/examples/page/ajax/accordion/AjaxAccordion.java)
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/ajax/accordion/AccordionPage.java?p2=click/trunk/click/examples/src/org/apache/click/examples/page/ajax/accordion/AccordionPage.java&p1=click/trunk/click/examples/src/org/apache/click/examples/page/ajax/accordion/AjaxAccordion.java&r1=962426&r2=962888&rev=962888&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/ajax/accordion/AjaxAccordion.java
(original)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/ajax/accordion/AccordionPage.java
Sat Jul 10 17:17:57 2010
@@ -27,10 +27,10 @@ import org.apache.click.element.JsScript
 import org.apache.click.examples.page.BorderPage;
 
 /**
- * Provides an Ajax demo of <a target="_blank" class="external" href="http://flowplayer.org/tools/demos/tabs/accordion.html">jQuery
Tools</a>
+ * Provides a demo of the <a target="_blank" class="external" href="http://flowplayer.org/tools/demos/tabs/accordion.html">jQuery
Tools</a>
  * Accordion.
  */
-public class AjaxAccordion extends BorderPage {
+public class AccordionPage extends BorderPage {
 
     private static final long serialVersionUID = 1L;
 
@@ -46,8 +46,8 @@ public class AjaxAccordion extends Borde
             headElements.add(new CssImport("/assets/css/tabs-accordion.css"));
 
             // Note the actual JavaScript necessary to setup the accordion is
-            // specified in the Page JavaScript template -> ajax-accordion.js.
-            headElements.add(new JsScript("/ajax/accordion/ajax-accordion.js", new HashMap()));
+            // specified in the Page JavaScript template -> accordion.js.
+            headElements.add(new JsScript("/ajax/accordion/accordion.js", new HashMap()));
 
             // Alternatively, the JsScript below could be used to add
             // the necessary JavaScript to setup the accordion, for example:

Added: click/trunk/click/examples/src/org/apache/click/examples/page/ajax/content/JsonResponsePage.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/ajax/content/JsonResponsePage.java?rev=962888&view=auto
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/ajax/content/JsonResponsePage.java
(added)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/ajax/content/JsonResponsePage.java
Sat Jul 10 17:17:57 2010
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.click.examples.page.ajax.content;
+
+import org.apache.click.Control;
+import org.apache.click.Partial;
+import org.apache.click.ajax.AjaxBehavior;
+import org.apache.click.control.ActionLink;
+import org.apache.click.examples.page.BorderPage;
+
+/**
+ * Demonstrates how a Partial can return a JSON response.
+ */
+public class JsonResponsePage extends BorderPage {
+
+    private static final long serialVersionUID = 1L;
+
+    private ActionLink link = new ActionLink("link", "here");
+
+    public JsonResponsePage() {
+        link.setId("link-id");
+
+        addControl(link);
+
+        // Add an Ajax behavior to the link. The behavior will be invoked when the
+        // link is clicked. See the basic-ajax-demo.htm template for the client-side
+        // Ajax code
+        link.addBehavior(new AjaxBehavior() {
+
+            @Override
+            public Partial onAction(Control source) {
+                // Formatted date instance that will be added to the
+                String now = format.currentDate("MMM, yyyy dd HH:MM:ss");
+
+                String msg = "{\"msg\": \"JSON returned at: \", \"date\": \"" + now + "\"}";
+                // Return a partial containing the message
+                return new Partial(msg, Partial.JSON);
+            }
+        });
+    }
+}

Added: click/trunk/click/examples/src/org/apache/click/examples/page/ajax/content/XmlResponsePage.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/ajax/content/XmlResponsePage.java?rev=962888&view=auto
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/ajax/content/XmlResponsePage.java
(added)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/ajax/content/XmlResponsePage.java
Sat Jul 10 17:17:57 2010
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.click.examples.page.ajax.content;
+
+import org.apache.click.Control;
+import org.apache.click.Partial;
+import org.apache.click.ajax.AjaxBehavior;
+import org.apache.click.control.ActionLink;
+import org.apache.click.examples.page.BorderPage;
+
+/**
+ * Demonstrates how a Partial can return an XML response.
+ */
+public class XmlResponsePage extends BorderPage {
+
+    private static final long serialVersionUID = 1L;
+
+    private ActionLink link = new ActionLink("link", "here");
+
+    public XmlResponsePage() {
+        link.setId("link-id");
+
+        addControl(link);
+
+        // Add an Ajax behavior to the link. The behavior will be invoked when the
+        // link is clicked. See the basic-ajax-demo.htm template for the client-side
+        // Ajax code
+        link.addBehavior(new AjaxBehavior() {
+
+            @Override
+            public Partial onAction(Control source) {
+                // Formatted date instance that will be added to the
+                String now = format.currentDate("MMM, yyyy dd HH:MM:ss");
+
+                String msg = "<payload>"
+                    + "<msg>XML returned at: </msg>"
+                    + "<date>" + now + "</date>"
+                    + "</payload>";
+                // Return a partial containing the message
+                return new Partial(msg, Partial.XML);
+            }
+        });
+    }
+}

Modified: click/trunk/click/examples/webapp/WEB-INF/menu.xml
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/webapp/WEB-INF/menu.xml?rev=962888&r1=962887&r2=962888&view=diff
==============================================================================
--- click/trunk/click/examples/webapp/WEB-INF/menu.xml (original)
+++ click/trunk/click/examples/webapp/WEB-INF/menu.xml Sat Jul 10 17:17:57 2010
@@ -151,10 +151,13 @@
     <menu label="Simple Form AJAX Demo" path="ajax/form/simple-form-ajax.htm"/>
     <menu label="Advanced Form AJAX Demo" path="ajax/form/advanced-form-ajax.htm"/>
     <menu separator="true"/>
-    <menu label="AJAX Accordion" path="ajax/accordion/ajax-accordion.htm"/>
-    <menu label="AJAX Auto Complete Field" path="ajax/auto-complete.htm"/>
-    <menu label="AJAX Live Scroller " path="ajax/scroller/ajax-live-scroller.htm"/>
-    <menu label="AJAX Select" path="ajax/select/ajax-select.htm"/>
+    <menu label="XML response" path="ajax/content/xml-response.htm"/>
+    <menu label="JSON response" path="ajax/content/json-response.htm"/>
+    <menu separator="true"/>
+    <menu label="Accordion" path="ajax/accordion/accordion.htm"/>
+    <menu label="Auto Complete Field" path="ajax/auto-complete.htm"/>
+    <menu label="Live Scroller " path="ajax/scroller/ajax-live-scroller.htm"/>
+    <menu label="Select" path="ajax/select/ajax-select.htm"/>
   </menu>
 
   <menu label=" Integration" path="#" imageSrc="/assets/images/cayenne.png">

Copied: click/trunk/click/examples/webapp/ajax/accordion/accordion.js (from r962419, click/trunk/click/examples/webapp/ajax/accordion/ajax-accordion.js)
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/webapp/ajax/accordion/accordion.js?p2=click/trunk/click/examples/webapp/ajax/accordion/accordion.js&p1=click/trunk/click/examples/webapp/ajax/accordion/ajax-accordion.js&r1=962419&r2=962888&rev=962888&view=diff
==============================================================================
--- click/trunk/click/examples/webapp/ajax/accordion/ajax-accordion.js (original)
+++ click/trunk/click/examples/webapp/ajax/accordion/accordion.js Sat Jul 10 17:17:57 2010
@@ -18,7 +18,7 @@
 // *#
 
 /**
- * The ajax-accordion Page JavaScript.
+ * The accordion Page JavaScript.
  */
 
 // Wait until browser DOM is loaded

Modified: click/trunk/click/examples/webapp/ajax/ajax-behavior.htm
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/webapp/ajax/ajax-behavior.htm?rev=962888&r1=962887&r2=962888&view=diff
==============================================================================
--- click/trunk/click/examples/webapp/ajax/ajax-behavior.htm (original)
+++ click/trunk/click/examples/webapp/ajax/ajax-behavior.htm Sat Jul 10 17:17:57 2010
@@ -14,7 +14,7 @@
             makeRequest();
 
             // Prevent the default browser behavior of navigating to the link
-            event.preventDefault();
+            return false;
         })
     })
 
@@ -37,7 +37,7 @@ to an Ajax request.
 
 <p/>
 
-Click $link to fetch the date using Ajax.
+Click $link to call the server using Ajax.
 
 <div id="result">
     <!-- Ajax response will be set here -->

Modified: click/trunk/click/examples/webapp/ajax/compare/jquery-ajax-demo.htm
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/webapp/ajax/compare/jquery-ajax-demo.htm?rev=962888&r1=962887&r2=962888&view=diff
==============================================================================
--- click/trunk/click/examples/webapp/ajax/compare/jquery-ajax-demo.htm (original)
+++ click/trunk/click/examples/webapp/ajax/compare/jquery-ajax-demo.htm Sat Jul 10 17:17:57
2010
@@ -26,7 +26,7 @@ $link
             makeRequest();
 
             // Prevent the default browser behavior of navigating to the link
-            event.preventDefault();
+            return false;
         })
     })
 
@@ -44,7 +44,7 @@ $link
         // based the value of the predefined parameter: 'actionLink'. The 'actionLink' parameter
         // value specifies the name of the ActionLink that was clicked. So we append
         // the 'actionLink' parameter and set the value as the ActionLink name -> 'link'.
-        var url = '$context/ajax/compare/javascript-ajax-demo.htm';
+        var url = '$context/ajax/compare/jquery-ajax-demo.htm';
         var extraData = 'link-id=1&actionLink=link';
         jQuery.get(url, extraData, function(data) {
             updateLog(data);

Modified: click/trunk/click/examples/webapp/ajax/compare/prototype-ajax-demo.htm
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/webapp/ajax/compare/prototype-ajax-demo.htm?rev=962888&r1=962887&r2=962888&view=diff
==============================================================================
--- click/trunk/click/examples/webapp/ajax/compare/prototype-ajax-demo.htm (original)
+++ click/trunk/click/examples/webapp/ajax/compare/prototype-ajax-demo.htm Sat Jul 10 17:17:57
2010
@@ -44,7 +44,7 @@ $link
         // value specifies the name of the ActionLink that was clicked. So we append
         // the 'actionLink' parameter and set the value as the ActionLink name -> 'link'.
         var extraData = 'link-id=1&actionLink=link';
-        var url = '$context/ajax/compare/javascript-ajax-demo.htm';
+        var url = '$context/ajax/compare/prototype-ajax-demo.htm';
         new Ajax.Request(url, {
             method:'get',
             parameters: extraData,

Added: click/trunk/click/examples/webapp/ajax/content/json-response.htm
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/webapp/ajax/content/json-response.htm?rev=962888&view=auto
==============================================================================
--- click/trunk/click/examples/webapp/ajax/content/json-response.htm (added)
+++ click/trunk/click/examples/webapp/ajax/content/json-response.htm Sat Jul 10 17:17:57 2010
@@ -0,0 +1,39 @@
+<script type="text/javascript" src="$context/assets/js/jquery-1.4.2.js"></script>
+
+<script type="text/javascript">
+    // Register a function that is invoked as soon as the DOM is loaded
+    jQuery(document).ready(function() {
+
+        // Register a 'click' handler that makes an Ajax request
+        jQuery("#link-id").click(function(event){
+            // Make ajax request
+            makeRequest();
+
+            // Prevent the default browser behavior of navigating to the link
+            return false;
+        })
+    })
+
+    function makeRequest() {
+        var link = jQuery('#link-id');
+        var extraData = link.attr('id') + '=1';
+        var url = link.attr('href');
+        jQuery.get(url, extraData, function(data) {
+            // 'data' is the response received from the server
+
+            // Extract the 'msg' and 'date' values from the JSON response and output the
result
+            var obj = jQuery.parseJSON(data);
+            jQuery("#result").html("<p class='infoMsg'>" + obj.msg + obj.date + "</p>");
+        }, {dataType:'json'});
+    }
+</script>
+
+This example shows how a Partial can return an <a href="http://www.json.org/" target="_blank">JSON</a>
response.
+
+<p/>
+
+Click $link to call the server using Ajax.
+
+<div id="result">
+    <!-- Ajax response will be set here -->
+</div>
\ No newline at end of file

Added: click/trunk/click/examples/webapp/ajax/content/xml-response.htm
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/webapp/ajax/content/xml-response.htm?rev=962888&view=auto
==============================================================================
--- click/trunk/click/examples/webapp/ajax/content/xml-response.htm (added)
+++ click/trunk/click/examples/webapp/ajax/content/xml-response.htm Sat Jul 10 17:17:57 2010
@@ -0,0 +1,41 @@
+<script type="text/javascript" src="$context/assets/js/jquery-1.4.2.js"></script>
+
+<script type="text/javascript">
+    // Register a function that is invoked as soon as the DOM is loaded
+    jQuery(document).ready(function() {
+
+        // Register a 'click' handler that makes an Ajax request
+        jQuery("#link-id").click(function(event){
+            // Make ajax request
+            makeRequest();
+
+            // Prevent the default browser behavior of navigating to the link
+            return false;
+        })
+    })
+
+    function makeRequest() {
+        var link = jQuery('#link-id');
+        var extraData = link.attr('id') + '=1';
+        var url = link.attr('href');
+        jQuery.get(url, extraData, function(data) {
+            // 'data' is the response received from the server
+
+            // Extract the <msg> and <date> values from the XML response and
output the result
+            var root = jQuery(data);
+            var msg = root.find('msg').text();
+            var date = root.find('date').text();
+            jQuery("#result").html("<p class='infoMsg'>" + msg + date + "</p>");
+        }, {dataType:'xml'});
+    }
+</script>
+
+This example shows how a Partial can return an XML response.
+
+<p/>
+
+Click $link to call the server using Ajax.
+
+<div id="result">
+    <!-- Ajax response will be set here -->
+</div>
\ No newline at end of file

Modified: click/trunk/click/examples/webapp/ajax/form/advanced-form-ajax.js
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/webapp/ajax/form/advanced-form-ajax.js?rev=962888&r1=962887&r2=962888&view=diff
==============================================================================
--- click/trunk/click/examples/webapp/ajax/form/advanced-form-ajax.js (original)
+++ click/trunk/click/examples/webapp/ajax/form/advanced-form-ajax.js Sat Jul 10 17:17:57
2010
@@ -31,11 +31,11 @@ jQuery(document).ready(function() {
 
     // Register a 'click' handler on the submit button
     jQuery("#form_save, #form_cancel").live('click', function(event){
-        // Prevent the default browser behavior of navigating to the link
-        event.preventDefault();
-
         // Post form to server
         postForm(event);
+
+        // Prevent the default browser behavior of navigating to the link
+        return false;
     })
 })
 

Modified: click/trunk/click/examples/webapp/ajax/form/simple-form-ajax.js
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/webapp/ajax/form/simple-form-ajax.js?rev=962888&r1=962887&r2=962888&view=diff
==============================================================================
--- click/trunk/click/examples/webapp/ajax/form/simple-form-ajax.js (original)
+++ click/trunk/click/examples/webapp/ajax/form/simple-form-ajax.js Sat Jul 10 17:17:57 2010
@@ -22,11 +22,11 @@ jQuery(document).ready(function() {
 
     // Register a 'click' handler on the submit button
     jQuery("#form_save").click(function(event){
-        // Prevent the default browser behavior of navigating to the link
-        event.preventDefault();
-
         // Post form to server
         postForm(event);
+
+        // Prevent the default browser behavior of navigating to the link
+        return false;
     })
 })
 

Modified: click/trunk/click/examples/webapp/ajax/page-action.htm
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/webapp/ajax/page-action.htm?rev=962888&r1=962887&r2=962888&view=diff
==============================================================================
--- click/trunk/click/examples/webapp/ajax/page-action.htm (original)
+++ click/trunk/click/examples/webapp/ajax/page-action.htm Sat Jul 10 17:17:57 2010
@@ -14,7 +14,7 @@
             makeRequest();
 
             // Prevent the default browser behavior of navigating to the link
-            event.preventDefault();
+            return false;
         })
     })
 
@@ -38,7 +38,7 @@ to an Ajax request.
 
 <p/>
 
-Click $link to fetch the date using Ajax.
+Click $link to call the server using Ajax.
 
 <div id="result">
     <!-- Ajax response will be set here -->

Modified: click/trunk/click/examples/webapp/ajax/table/table-ajax-demo.js
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/webapp/ajax/table/table-ajax-demo.js?rev=962888&r1=962887&r2=962888&view=diff
==============================================================================
--- click/trunk/click/examples/webapp/ajax/table/table-ajax-demo.js (original)
+++ click/trunk/click/examples/webapp/ajax/table/table-ajax-demo.js Sat Jul 10 17:17:57 2010
@@ -24,9 +24,6 @@ jQuery(document).ready(function() {
     // Note: the 'live' binding is a jQuery function that keeps the event bound even if the
Table DOM is replaced
     // http://api.jquery.com/live/
     jQuery("#table td a").live('click', function(event){
-        // Prevent the default browser behavior of navigating to the link
-        event.preventDefault();
-
         var callServer = true;
         if (jQuery(event.target).text()=="Delete") {
             callServer = window.confirm('Please confirm delete');
@@ -36,6 +33,9 @@ jQuery(document).ready(function() {
             // Make ajax request
             editCustomer(event);
         }
+
+        // Prevent the default browser behavior of navigating to the link
+        event.preventDefault();
     })
 
     // Register a 'live' click handler on the sorting links of the table header (<th>),
@@ -43,10 +43,11 @@ jQuery(document).ready(function() {
     // Note: the 'live' binding is a jQuery function that keeps the event bound even if the
Table DOM is replaced
     // http://api.jquery.com/live/
     jQuery("#table th a, .pagelinks a").live('click', function(event){
-        // Prevent the default browser behavior of navigating to the link
-        event.preventDefault();
         // Make ajax request
         sortTable(event);
+
+        // Prevent the default browser behavior of navigating to the link
+        return false;
     })
 })
 



Mime
View raw message