click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r953978 - in /click/trunk/click/examples: src/org/apache/click/examples/page/ajax/BasicAjaxDemoPage.java webapp/WEB-INF/menu.xml webapp/ajax/basic-ajax-demo.htm
Date Sat, 12 Jun 2010 09:56:58 GMT
Author: sabob
Date: Sat Jun 12 09:56:58 2010
New Revision: 953978

URL: http://svn.apache.org/viewvc?rev=953978&view=rev
Log:
added a basic ajax demo. CLK-653

Added:
    click/trunk/click/examples/src/org/apache/click/examples/page/ajax/BasicAjaxDemoPage.java
    click/trunk/click/examples/webapp/ajax/basic-ajax-demo.htm
Modified:
    click/trunk/click/examples/webapp/WEB-INF/menu.xml

Added: click/trunk/click/examples/src/org/apache/click/examples/page/ajax/BasicAjaxDemoPage.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/ajax/BasicAjaxDemoPage.java?rev=953978&view=auto
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/ajax/BasicAjaxDemoPage.java
(added)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/ajax/BasicAjaxDemoPage.java
Sat Jun 12 09:56:58 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;
+
+import java.util.HashMap;
+import java.util.Map;
+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;
+
+/**
+ * Basic BasicAjaxDemoPage example using the jQuery JavaScript library.
+ */
+public class BasicAjaxDemoPage extends BorderPage {
+
+    private static final long serialVersionUID = 1L;
+
+    private ActionLink link = new ActionLink("link", "here");
+
+    public BasicAjaxDemoPage() {
+        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() {
+
+            public Partial onAction(Control source) {
+                // Formatted date instance that will be added to the
+                String now = format.currentDate("MMM, yyyy dd HH:MM:ss");
+
+                // Return a partial containing the formatted date
+                return new Partial(now, Partial.HTML);
+            }
+        });
+    }
+}

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=953978&r1=953977&r2=953978&view=diff
==============================================================================
--- click/trunk/click/examples/webapp/WEB-INF/menu.xml (original)
+++ click/trunk/click/examples/webapp/WEB-INF/menu.xml Sat Jun 12 09:56:58 2010
@@ -138,6 +138,7 @@
   </menu>
 
   <menu label="Ajax" path="#" imageSrc="/assets/images/lightning.png">
+    <menu label="Basic AJAX Demo" path="ajax/basic-ajax-demo.htm"/>
     <menu label="AJAX Accordion" path="ajax/ajax-accordion.htm"/>
     <menu label="AJAX Auto Complete Field" path="ajax/auto-complete.htm"/>
     <menu label="AJAX Live Scroller " path="ajax/ajax-live-scroller.htm"/>

Added: click/trunk/click/examples/webapp/ajax/basic-ajax-demo.htm
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/webapp/ajax/basic-ajax-demo.htm?rev=953978&view=auto
==============================================================================
--- click/trunk/click/examples/webapp/ajax/basic-ajax-demo.htm (added)
+++ click/trunk/click/examples/webapp/ajax/basic-ajax-demo.htm Sat Jun 12 09:56:58 2010
@@ -0,0 +1,33 @@
+<script type="text/javascript" src="$context/assets/js/jquery-1.3.2.js"></script>
+
+<script type="text/javascript">
+    // This example uses jQuery for making Ajax requests: http://api.jquery.com/jQuery.ajax/
+
+    // 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(){
+            // Make ajax request
+            makeRequest();
+
+            // Return false to prevent the default browser behavior of following the link
href
+            return false;
+        })
+    })
+
+    function makeRequest() {
+        jQuery.ajax({
+            type: "GET",
+            url: "$context$path", // context and path are Velocity variables passed to this
template
+            data: "actionLink=link&link-id=1",
+            success: function(data) {
+                // The data argument contains the formatted date instance returned
+                // by the page Partial response
+                alert(data);
+            }
+        })
+    }
+</script>
+
+Click $link to fetch date with Ajax
\ No newline at end of file



Mime
View raw message