You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2010/07/10 14:30:00 UTC
svn commit: r962830 - in /click/trunk/click/examples:
src/org/apache/click/examples/page/ajax/ webapp/WEB-INF/ webapp/ajax/
Author: sabob
Date: Sat Jul 10 12:29:59 2010
New Revision: 962830
URL: http://svn.apache.org/viewvc?rev=962830&view=rev
Log:
added pageAction ajax demo
Added:
click/trunk/click/examples/src/org/apache/click/examples/page/ajax/AjaxBehaviorPage.java
- copied, changed from r962426, click/trunk/click/examples/src/org/apache/click/examples/page/ajax/AjaxDemoPage.java
click/trunk/click/examples/src/org/apache/click/examples/page/ajax/PageActionPage.java
click/trunk/click/examples/webapp/ajax/ajax-behavior.htm
click/trunk/click/examples/webapp/ajax/page-action.htm
Removed:
click/trunk/click/examples/src/org/apache/click/examples/page/ajax/AjaxDemoPage.java
click/trunk/click/examples/webapp/ajax/ajax-demo.htm
Modified:
click/trunk/click/examples/webapp/WEB-INF/menu.xml
Copied: click/trunk/click/examples/src/org/apache/click/examples/page/ajax/AjaxBehaviorPage.java (from r962426, click/trunk/click/examples/src/org/apache/click/examples/page/ajax/AjaxDemoPage.java)
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/ajax/AjaxBehaviorPage.java?p2=click/trunk/click/examples/src/org/apache/click/examples/page/ajax/AjaxBehaviorPage.java&p1=click/trunk/click/examples/src/org/apache/click/examples/page/ajax/AjaxDemoPage.java&r1=962426&r2=962830&rev=962830&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/ajax/AjaxDemoPage.java (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/ajax/AjaxBehaviorPage.java Sat Jul 10 12:29:59 2010
@@ -25,15 +25,20 @@ import org.apache.click.control.ActionLi
import org.apache.click.examples.page.BorderPage;
/**
- * Basic BasicAjaxDemoPage example using the jQuery JavaScript library.
+ * Demonstrates how to handle AJAX requests with an Ajax Behavior. The Behavior
+ * is added to the ActionLink and its onAction method is invoked to handle the
+ * AJAX request. The onAction method returns a Partial response that is streamed
+ * back to the browser.
+ *
+ * The client-side is implemented using the jQuery library.
*/
-public class AjaxDemoPage extends BorderPage {
+public class AjaxBehaviorPage extends BorderPage {
private static final long serialVersionUID = 1L;
private ActionLink link = new ActionLink("link", "here");
- public AjaxDemoPage() {
+ public AjaxBehaviorPage() {
link.setId("link-id");
addControl(link);
Added: click/trunk/click/examples/src/org/apache/click/examples/page/ajax/PageActionPage.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/ajax/PageActionPage.java?rev=962830&view=auto
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/ajax/PageActionPage.java (added)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/ajax/PageActionPage.java Sat Jul 10 12:29:59 2010
@@ -0,0 +1,59 @@
+/*
+ * 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 org.apache.click.Partial;
+import org.apache.click.control.ActionLink;
+import org.apache.click.examples.page.BorderPage;
+
+/**
+ * Demonstrates how a Page Action can be used to handle an AJAX request.
+ * The Page Action is invoked by Click to handle the AJAX request.
+ * The Page Action method returns a Partial response that is streamed back to the
+ * browser.
+ *
+ * A Page Action is a regular method defined on a Page with the following signature:
+ * - the method must take no arguments
+ * - the method must return a Partial
+ *
+ * PageActions provide the simplest way to handle Ajax requests.
+ *
+ * The client-side is implemented using the jQuery library.
+ */
+public class PageActionPage extends BorderPage {
+
+ private static final long serialVersionUID = 1L;
+
+ public PageActionPage() {
+ ActionLink link = new ActionLink("link", "here");
+ link.setId("link-id");
+ addControl(link);
+ }
+
+ // Note the pageAction method signature: a no-arg method returning a Partial
+ public Partial onLinkClicked() {
+ // Formatted date instance that will be added to the
+ String now = format.currentDate("MMM, yyyy dd HH:MM:ss");
+
+ String msg = "PageAction method <tt>onLinkClicked()</tt> invoked at: "
+ + now;
+ // Return a partial containing the message
+ return new Partial(msg, 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=962830&r1=962829&r2=962830&view=diff
==============================================================================
--- click/trunk/click/examples/webapp/WEB-INF/menu.xml (original)
+++ click/trunk/click/examples/webapp/WEB-INF/menu.xml Sat Jul 10 12:29:59 2010
@@ -139,7 +139,8 @@
</menu>
<menu label="Ajax" path="#" imageSrc="/assets/images/lightning.png">
- <menu label="AJAX Demo" path="ajax/ajax-demo.htm"/>
+ <menu label="Ajax Demo - Behavior" path="ajax/ajax-behavior.htm"/>
+ <menu label="Ajax Demo - Page Action" path="ajax/page-action.htm"/>
<menu separator="true"/>
<menu label="JavaScript AJAX Demo" path="ajax/compare/javascript-ajax-demo.htm"/>
<menu label="jQuery AJAX Demo" path="ajax/compare/jquery-ajax-demo.htm"/>
Added: 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=962830&view=auto
==============================================================================
--- click/trunk/click/examples/webapp/ajax/ajax-behavior.htm (added)
+++ click/trunk/click/examples/webapp/ajax/ajax-behavior.htm Sat Jul 10 12:29:59 2010
@@ -0,0 +1,44 @@
+<script type="text/javascript" src="$context/assets/js/jquery-1.4.2.js"></script>
+
+<script type="text/javascript">
+ // This example uses jQuery for making Ajax requests:
+ // http://api.jquery.com/jQuery.get/
+ // 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(event){
+ // Make ajax request
+ makeRequest();
+
+ // Prevent the default browser behavior of navigating to the link
+ event.preventDefault();
+ })
+ })
+
+ 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
+
+ // We select the div element with the ID 'result' and set its
+ // content to the server response
+ jQuery("#result").html("<p class='infoMsg'>" + data + "</p>");
+ });
+ }
+</script>
+
+This example demonstrates how an AjaxBehavior can be used to handle and respond
+to an Ajax request.
+
+<p/>
+
+Click $link to fetch the date 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/page-action.htm
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/webapp/ajax/page-action.htm?rev=962830&view=auto
==============================================================================
--- click/trunk/click/examples/webapp/ajax/page-action.htm (added)
+++ click/trunk/click/examples/webapp/ajax/page-action.htm Sat Jul 10 12:29:59 2010
@@ -0,0 +1,45 @@
+<script type="text/javascript" src="$context/assets/js/jquery-1.4.2.js"></script>
+
+<script type="text/javascript">
+ // This example uses jQuery for making Ajax requests:
+ // http://api.jquery.com/jQuery.get/
+ // 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(event){
+ // Make ajax request
+ makeRequest();
+
+ // Prevent the default browser behavior of navigating to the link
+ event.preventDefault();
+ })
+ })
+
+ function makeRequest() {
+ var link = jQuery('#link-id');
+ var url = link.attr('href');
+ // Set the pageAction to the onLinkClicked method in the Java Page class.
+ var extraData = 'pageAction=onLinkClicked';
+ jQuery.get(url, extraData, function(data) {
+ // 'data' is the response received from the server
+
+ // We select the div element with the ID 'result' and set its
+ // content to the server response
+ jQuery("#result").html("<p class='infoMsg'>" + data + "</p>");
+ });
+ }
+</script>
+
+This example demonstrates how a PageAction can be used to handle and respond
+to an Ajax request.
+
+<p/>
+
+Click $link to fetch the date using Ajax.
+
+<div id="result">
+ <!-- Ajax response will be set here -->
+</div>