You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by th...@apache.org on 2017/04/02 21:59:23 UTC
tapestry-5 git commit: TAP5-2225: fixing getEventUrl and improving
@PublishEvent JavaDoc
Repository: tapestry-5
Updated Branches:
refs/heads/5.4.x b8ed0cd75 -> c8e8fd6d2
TAP5-2225: fixing getEventUrl and improving @PublishEvent JavaDoc
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/c8e8fd6d
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/c8e8fd6d
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/c8e8fd6d
Branch: refs/heads/5.4.x
Commit: c8e8fd6d206352dbb91d684a9251dd036efd1fe7
Parents: b8ed0cd
Author: Thiago H. de Paula Figueiredo <th...@apache.org>
Authored: Sun Apr 2 18:59:12 2017 -0300
Committer: Thiago H. de Paula Figueiredo <th...@apache.org>
Committed: Sun Apr 2 18:59:12 2017 -0300
----------------------------------------------------------------------
.../example/testapp/pages/NestedObjectDemo.java | 1 +
.../tapestry5/annotations/PublishEvent.java | 22 ++++-
.../org/apache/tapestry5/t5-core-dom.coffee | 87 ++++++++++----------
3 files changed, 63 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c8e8fd6d/tapestry-beanvalidator/src/test/java/org/example/testapp/pages/NestedObjectDemo.java
----------------------------------------------------------------------
diff --git a/tapestry-beanvalidator/src/test/java/org/example/testapp/pages/NestedObjectDemo.java b/tapestry-beanvalidator/src/test/java/org/example/testapp/pages/NestedObjectDemo.java
index f365bdd..37087ba 100644
--- a/tapestry-beanvalidator/src/test/java/org/example/testapp/pages/NestedObjectDemo.java
+++ b/tapestry-beanvalidator/src/test/java/org/example/testapp/pages/NestedObjectDemo.java
@@ -24,6 +24,7 @@ public class NestedObjectDemo
@Inject
private AlertManager alertManager;
+ @Property
private boolean enableClientValidation;
public void onActivate(boolean enableClientValidation) {
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c8e8fd6d/tapestry-core/src/main/java/org/apache/tapestry5/annotations/PublishEvent.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/annotations/PublishEvent.java b/tapestry-core/src/main/java/org/apache/tapestry5/annotations/PublishEvent.java
index 18239d4..2d06588 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/annotations/PublishEvent.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/annotations/PublishEvent.java
@@ -24,22 +24,36 @@ import java.lang.annotation.Target;
import org.apache.tapestry5.ioc.annotations.UseWith;
/**
+ * <p>
* Marks an event handler method to be published as an event to be called in JavaScript
- * through the <code>t5/core/triggerServerEvent</code> function.
+ * through the <code>t5/core/ajax</code> function when the <code>options</code>
+ * parameter has an <code>element</code> attribute.
+ * <p>
*
+ * <p>
+ * The logic for obtaining the URL is actually located implemented in the
+ * <code>t5/core/dom.getEventUrl(eventName, element)</code> function.
+ * </p>
+ *
+ * <p>
* The event information is stored in JSON format inside the
* {@value org.apache.tapestry5.TapestryConstants#COMPONENT_EVENTS_ATTRIBUTE_NAME} attribute.
+ * </p>
*
+ * <p>
* When used in a component method, the component must render at least one element,
- * and that's what get the
+ * and that's what gets the
* {@value org.apache.tapestry5.TapestryConstants#COMPONENT_EVENTS_ATTRIBUTE_NAME} attribute above.
* If it doesn't, an exception will be thrown.
+ * </p>
*
- * When used in a page method, the page must render an <body> element,
- * {@value org.apache.tapestry5.TapestryConstants#COMPONENT_EVENTS_ATTRIBUTE_NAME}. If it doesn't,
+ * <p>
+ * When used in a page method, the page must render an <body> element. If it doesn't,
* an exception will be thrown.
+ * </p>
*
* @since 5.4.2
+ * @see https://tapestry.apache.org/ajax-and-zones.html#AjaxandZones-Invokingserver-sideeventhandlermethodsfromJavaScript
*/
@Target(ElementType.METHOD)
@Retention(RUNTIME)
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/c8e8fd6d/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee b/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee
index 97b2a06..ae29d8c 100644
--- a/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee
+++ b/tapestry-core/src/main/preprocessed-coffeescript/org/apache/tapestry5/t5-core-dom.coffee
@@ -890,7 +890,51 @@ define ["underscore", "./utils", "./events", "jquery"],
value = {}
#endif
+ # Returns the URL of a component event based on its name and an optional element
+ # or null if the event information is not found. When the element isn't passed
+ # or it's null, the event data is taken from the <body> element.
+ #
+ # * eventName - (string) name of the component event
+ # * element - (object) HTML DOM element to be used as the beginning of the event data search. Optional.
+ getEventUrl = (eventName, element) ->
+
+ if not (eventName?)
+ throw 'dom.getEventUrl: the eventName parameter cannot be null'
+
+ if not _.isString eventName
+ throw 'dom.getEventUrl: the eventName parameter should be a string'
+
+ eventName = eventName.toLowerCase()
+
+#if jquery
+ if element instanceof jQuery
+ element = element[0];
+#endif
+
+ if element is null
+ element = document.getElementsByTagName('body')[0]
+
+ # Look for event data in itself first, then in the preceding siblings
+ # if not found
+ url = null
+
+ while not url? and element.previousElementSibling?
+ data = getDataAttributeAsObject(element, 'component-events')
+ url = data?[eventName]?.url
+ element = element.previousElementSibling
+
+ if not url?
+
+ # Look at parent elements recursively
+ while not url? and element.parentElement?
+ data = getDataAttributeAsObject(element, 'component-events')
+ url = data?[eventName]?.url
+ element = element.parentElement;
+
_.extend exports,
+
+ getEventUrl: getEventUrl
+
wrap: wrapElement
create: createElement
@@ -923,49 +967,6 @@ define ["underscore", "./utils", "./events", "jquery"],
#endif
onevent elements, events, match, handler
- # Returns the URL of a component event based on its name and an optional element
- # or null if the event information is not found. When the element isn't passed
- # or it's null, the event data is taken from the <body> element.
- #
- # * eventName - (string) name of the component event
- # * element - (object) HTML DOM element to be used as the beginning of the event data search. Optional.
- getEventUrl: (eventName, element) ->
-
- if not (eventName?)
- throw 'dom.getEventUrl: the eventName parameter cannot be null'
-
- if not _.isString eventName
- throw 'dom.getEventUrl: the eventName parameter should be a string'
-
- eventName = eventName.toLowerCase()
-
-#if jquery
- if element instanceof jQuery
- element = element[0];
-#endif
-
- if element is null
- element = document.getElementsByTagName('body')[0]
-
- # Look for event data in itself first, then in the preceding siblings
- # if not found
- url = null
-
- while not url? and element.previousElementSibling?
- data = getDataAttributeAsObject(element, 'component-events')
- url = data?[eventName]?.url
- element = element.previousElementSibling
-
- if not url?
-
- # Look at parent elements recursively
- while not url? and element.parentElement?
- data = getDataAttributeAsObject(element, 'component-events')
- url = data?[eventName]?.url
- element = element.parentElement;
-
- return url;
-
# onDocument() is used to add an event handler to the document object; this is used
# for global (or default) handlers.
# Returns a function of no parameters that removes any added handlers.