Return-Path: Delivered-To: apmail-incubator-click-commits-archive@minotaur.apache.org Received: (qmail 66548 invoked from network); 8 Jun 2009 18:50:44 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 8 Jun 2009 18:50:44 -0000 Received: (qmail 43668 invoked by uid 500); 8 Jun 2009 18:50:55 -0000 Delivered-To: apmail-incubator-click-commits-archive@incubator.apache.org Received: (qmail 43655 invoked by uid 500); 8 Jun 2009 18:50:55 -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 43645 invoked by uid 99); 8 Jun 2009 18:50:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Jun 2009 18:50:55 +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; Mon, 08 Jun 2009 18:50:42 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id EBDE223888A0; Mon, 8 Jun 2009 18:50:21 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r782724 - in /incubator/click/trunk/click/examples: src/org/apache/click/examples/page/ajax/AjaxSelect.java src/org/apache/click/examples/page/pageflow/StartPage.java webapp/ajax/ajax-customer.htm webapp/ajax/ajax-select.js Date: Mon, 08 Jun 2009 18:50:21 -0000 To: click-commits@incubator.apache.org From: sabob@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090608185021.EBDE223888A0@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sabob Date: Mon Jun 8 18:50:21 2009 New Revision: 782724 URL: http://svn.apache.org/viewvc?rev=782724&view=rev Log: replaced Rico with Prototype for Ajax select demo Added: incubator/click/trunk/click/examples/webapp/ajax/ajax-select.js Modified: incubator/click/trunk/click/examples/src/org/apache/click/examples/page/ajax/AjaxSelect.java incubator/click/trunk/click/examples/src/org/apache/click/examples/page/pageflow/StartPage.java incubator/click/trunk/click/examples/webapp/ajax/ajax-customer.htm Modified: incubator/click/trunk/click/examples/src/org/apache/click/examples/page/ajax/AjaxSelect.java URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/page/ajax/AjaxSelect.java?rev=782724&r1=782723&r2=782724&view=diff ============================================================================== --- incubator/click/trunk/click/examples/src/org/apache/click/examples/page/ajax/AjaxSelect.java (original) +++ incubator/click/trunk/click/examples/src/org/apache/click/examples/page/ajax/AjaxSelect.java Mon Jun 8 18:50:21 2009 @@ -18,13 +18,16 @@ */ package org.apache.click.examples.page.ajax; -import java.util.Iterator; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.annotation.Resource; import org.apache.click.control.Option; import org.apache.click.control.Select; +import org.apache.click.element.JsImport; +import org.apache.click.element.JsScript; import org.apache.click.examples.domain.Customer; import org.apache.click.examples.page.BorderPage; import org.apache.click.examples.service.CustomerService; @@ -38,8 +41,6 @@ @Component public class AjaxSelect extends BorderPage { - public String jsInclude = "ajax/ajax-select-include.htm"; - public Select customerSelect = new Select("customerSelect"); @Resource(name="customerService") @@ -49,8 +50,6 @@ public void onInit() { super.onInit(); - customerSelect.setAttribute("onchange", "onCustomerChange(this);"); - List customerList = customerService.getCustomersSortedByName(8); for (Customer customer : customerList) { customerSelect.add(new Option(customer.getId(), customer.getName())); @@ -59,4 +58,33 @@ customerSelect.setSize(customerList.size()); } + public List getHeadElements() { + if (headElements == null) { + headElements = super.getHeadElements(); + + // Include the prototype.js library which is made available under + // the web folder "/click/prototype/" + headElements.add(new JsImport("/click/prototype/prototype.js")); + + // Create a model to pass to the Page JavaScript template. The + // template recognizes three Velocity variables: + // $context, $selector and $target + Map model = new HashMap(); + + // Add the application context path -> "/click-examples" + model.put("context", getContext().getRequest().getContextPath()); + + // Add a CSS selector, in this case the customerSelect ID attribute + model.put("selector", customerSelect.getId()); + + // Add the ID of a target element in the Page template to replace + // with new data, in this example the target is 'customerDetails' + model.put("target", "customerDetails"); + + // Include the Page associated JavaScript template + headElements.add(new JsScript("/ajax/ajax-select.js", model)); + } + + return headElements; + } } Modified: incubator/click/trunk/click/examples/src/org/apache/click/examples/page/pageflow/StartPage.java URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/page/pageflow/StartPage.java?rev=782724&r1=782723&r2=782724&view=diff ============================================================================== --- incubator/click/trunk/click/examples/src/org/apache/click/examples/page/pageflow/StartPage.java (original) +++ incubator/click/trunk/click/examples/src/org/apache/click/examples/page/pageflow/StartPage.java Mon Jun 8 18:50:21 2009 @@ -18,8 +18,10 @@ */ package org.apache.click.examples.page.pageflow; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.annotation.Resource; import org.apache.click.control.Form; @@ -27,6 +29,8 @@ import org.apache.click.control.Select; import org.apache.click.control.Submit; import org.apache.click.control.TextArea; +import org.apache.click.element.JsImport; +import org.apache.click.element.JsScript; import org.apache.click.examples.control.InvestmentSelect; import org.apache.click.examples.domain.CourseBooking; import org.apache.click.examples.domain.Customer; @@ -44,10 +48,7 @@ @Component public class StartPage extends BorderPage { - public String jsInclude = "ajax/ajax-select-include.htm"; - public String bodyOnload = "registerAjax();"; public Form form = new Form(); - private Select customerSelect; private DateField dateField; private Select courseSelect; @@ -65,7 +66,6 @@ customerSelect = new Select("Customer"); customerSelect.setRequired(true); - customerSelect.setAttribute("onchange", "onCustomerChange(this);"); form.add(customerSelect); dateField = new DateField("Booking Date"); @@ -138,6 +138,41 @@ return true; } + /** + * Return the Page JavaScript resources. + * + * @see org.apache.click.Page#getHeadElements() + */ + public List getHeadElements() { + if (headElements == null) { + headElements = super.getHeadElements(); + + // Include the prototype.js library which is made available under + // the web folder "/click/prototype/" + headElements.add(new JsImport("/click/prototype/prototype.js")); + + // Create a model to pass to the Page JavaScript template. The + // template recognizes three Velocity variables: + // $context, $selector and $target + Map model = new HashMap(); + + // Add the application context path -> "/click-examples" + model.put("context", getContext().getRequest().getContextPath()); + + // Add a CSS selector, in this case the customerSelect ID attribute + model.put("selector", customerSelect.getId()); + + // Add the ID of a target element in the Page template to replace + // with new data, in this example the target is 'customerDetails' + model.put("target", "customerDetails"); + + // Include the ajax-select.js template + headElements.add(new JsScript("/ajax/ajax-select.js", model)); + } + + return headElements; + } + // --------------------------------------------------------- Public Methods public void setCourseBooking(CourseBooking courseBooking) { Modified: incubator/click/trunk/click/examples/webapp/ajax/ajax-customer.htm URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/webapp/ajax/ajax-customer.htm?rev=782724&r1=782723&r2=782724&view=diff ============================================================================== --- incubator/click/trunk/click/examples/webapp/ajax/ajax-customer.htm (original) +++ incubator/click/trunk/click/examples/webapp/ajax/ajax-customer.htm Mon Jun 8 18:50:21 2009 @@ -1,5 +1,3 @@ - - - - -#if ($customer) +#if ($customer) @@ -47,7 +43,5 @@ -
Name $format.string($customer.name)Date Joined $format.date($customer.dateJoined, "dd MMM yyyy")
#end -
-
\ No newline at end of file + Added: incubator/click/trunk/click/examples/webapp/ajax/ajax-select.js URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/webapp/ajax/ajax-select.js?rev=782724&view=auto ============================================================================== --- incubator/click/trunk/click/examples/webapp/ajax/ajax-select.js (added) +++ incubator/click/trunk/click/examples/webapp/ajax/ajax-select.js Mon Jun 8 18:50:21 2009 @@ -0,0 +1,47 @@ +// 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. + +/** + * The ajax-select Page JavaScript. + */ + +// Wait until browser DOM is loaded +document.observe("dom:loaded", function() { + + // Observe the selected element's "change" event, which triggers the given function + $('$selector').observe('change', function(event){ + var select = Event.element(event); + onCustomerChange(select); + }); + + // This function uses an Ajax request to retrieve customer details that matches + // the ID value of a select element + function onCustomerChange(select) { + // The Ajax url points to the AjaxCustomer Click Page + new Ajax.Request('${context}/ajax/ajax-customer.htm', { + method: 'get', + parameters: {customerId : select.value}, + onSuccess: function(transport){ + // On a successful request, update the given target with the server response + $('$target').update(transport.responseText); + }, + onFailure: function(){ + alert('An error occurred.') + } + }); + } +});