You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2008/02/27 01:11:33 UTC
svn commit: r631432 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry/internal/transform/ site/apt/guide/
test/app1/ test/java/org/apache/tapestry/integration/
test/java/org/apache/tapestry/integration/app1/pages/
Author: hlship
Date: Tue Feb 26 16:11:29 2008
New Revision: 631432
URL: http://svn.apache.org/viewvc?rev=631432&view=rev
Log:
TAPESTRY-1999: Allow the context for an event to be specified as a List as well as an Object array
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ListEventContextDemo.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/ListEventContextDemo.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/transform/OnEventWorker.java
tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/event.apt
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/Start.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/transform/OnEventWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/transform/OnEventWorker.java?rev=631432&r1=631431&r2=631432&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/transform/OnEventWorker.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/transform/OnEventWorker.java Tue Feb 26 16:11:29 2008
@@ -20,6 +20,7 @@
import org.apache.tapestry.model.MutableComponentModel;
import org.apache.tapestry.services.*;
+import java.util.Arrays;
import java.util.List;
/**
@@ -32,6 +33,8 @@
static final String EVENT_CONTEXT_TYPE = EventContext.class.getName();
+ static final String LIST_TYPE = List.class.getName();
+
private final static int ANY_NUMBER_OF_PARAMETERS = -1;
public void transform(final ClassTransformation transformation, MutableComponentModel model)
@@ -155,7 +158,7 @@
{
String soloType = types[0];
- if (soloType.equals(OBJECT_ARRAY_TYPE) || soloType.equals(EVENT_CONTEXT_TYPE))
+ if (soloType.equals(OBJECT_ARRAY_TYPE) || soloType.equals(EVENT_CONTEXT_TYPE) || soloType.equals(LIST_TYPE))
return ANY_NUMBER_OF_PARAMETERS;
}
@@ -185,6 +188,14 @@
if (type.equals(EVENT_CONTEXT_TYPE))
{
builder.add("$1.getEventContext()");
+ continue;
+ }
+
+ // Added for TAPESTRY-1999
+
+ if (type.equals(LIST_TYPE))
+ {
+ builder.add("%s.asList($1.getContext())", Arrays.class.getName());
continue;
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/event.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/event.apt?rev=631432&r1=631431&r2=631432&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/event.apt (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/site/apt/guide/event.apt Tue Feb 26 16:11:29 2008
@@ -163,16 +163,24 @@
If you have multiple context values (by binding a list or array of objects to the ActionLink's
context parameter), then each one, in order, will be added to the URL.
- When an event handler method is invoked, a
- {{{coercion.html}coercion}} from string to the actual type occurs. An event handler method will only be invoked
- <if the context contains at least as many values as the method has parameters>. Methods with too many parameters
- will be silently skipped.
-
- Alternately, an event handler method may take a parameter of type java.lang.Object[]. This parameter
- will receive the entire context array. This is useful when, for example, the context
- is of different lengths at different times. You should use either explicit, typed parameters or
- a single parameter of type Object[].
-
+ When an event handler method is invoked, the strings are converted back into
+ values, or even objects. A
+ {{{../../apidocs/org/apache/tapestry/ValueEncoder.html}ValueEncoder}} is used to convert between client-side strings
+ and server-side objects. The {{{../../apidocs/org/apache/tapestry/services/ValueEncoderSource.html}ValueEncoderSource}} service
+ provides the necessary value encoders.
+
+* Method Matching
+
+ An event handler method will only be invoked
+ <if the context contains at least as many values as the method has parameters>. Methods with too many parameters
+ will be silently skipped.
+
+* Collections
+
+ To designate that an event handler method should be invoked regardless of how many context parameters are available,
+ change the method to accept a <single> parameter of type Object[], type List, or
+ {{{../../apidocs/org/apache/tapestry/EventContext.html}EventContext}}.
+
Event Bubbling
The event will bubble up the hierarchy, until it is aborted. The event is aborted
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ListEventContextDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ListEventContextDemo.tml?rev=631432&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ListEventContextDemo.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ListEventContextDemo.tml Tue Feb 26 16:11:29 2008
@@ -0,0 +1,12 @@
+<html t:type="Border"
+ xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+
+ <h1>List Event Context</h1>
+
+
+ <ul id="eventcontext">
+ <li t:type="loop" source="eventContext" value="var:value">${var:value}</li>
+ </ul>
+
+
+</html>
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml?rev=631432&r1=631431&r2=631432&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml Tue Feb 26 16:11:29 2008
@@ -46,6 +46,12 @@
-- transition to HTTPS
</li>
+ <li>
+ <t:pagelink page="listeventcontextdemo" context="demoContext">List Event Context Demo</t:pagelink>
+ -- using a List for catch-all event context parameters
+
+ </li>
+
</ul>
</html>
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java?rev=631432&r1=631431&r2=631432&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java Tue Feb 26 16:11:29 2008
@@ -1768,7 +1768,9 @@
assertText("activePageName", "music/Details");
}
- /** TAPESTRY-1869 */
+ /**
+ * TAPESTRY-1869
+ */
public void null_fields_and_bean_editor()
{
start("Number BeanEditor Demo");
@@ -1784,5 +1786,15 @@
clickAndWait(SUBMIT);
assertSourcePresent("<div class=\"t-beandisplay-value\">237</div>");
+ }
+
+ /**
+ * TAPESTRY-1999
+ */
+ public void list_as_event_context()
+ {
+ start("List Event Context Demo");
+
+ assertTextSeries("//ul[@id='eventcontext']/li[%d]", 1, "1", "2", "3");
}
}
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/ListEventContextDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/ListEventContextDemo.java?rev=631432&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/ListEventContextDemo.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/ListEventContextDemo.java Tue Feb 26 16:11:29 2008
@@ -0,0 +1,32 @@
+// Copyright 2008 The Apache Software Foundation
+//
+// Licensed 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.tapestry.integration.app1.pages;
+
+import java.util.List;
+
+public class ListEventContextDemo
+{
+ private List _eventContext;
+
+ public List getEventContext()
+ {
+ return _eventContext;
+ }
+
+ void onActivate(List context)
+ {
+ _eventContext = context;
+ }
+}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/Start.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/Start.java?rev=631432&r1=631431&r2=631432&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/Start.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/app1/pages/Start.java Tue Feb 26 16:11:29 2008
@@ -17,6 +17,7 @@
import org.apache.tapestry.annotations.InjectPage;
import org.apache.tapestry.ioc.internal.util.CollectionFactory;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -62,7 +63,8 @@
private static final List<Item> ITEMS = CollectionFactory.newList(
new Item("actionpage", "Action Page", "tests fixture for ActionLink component"),
- new Item("numberbeaneditordemo", "Number BeanEditor Demo", "use of nulls and wrapper types with BeanEditor"),
+ new Item("numberbeaneditordemo", "Number BeanEditor Demo",
+ "use of nulls and wrapper types with BeanEditor"),
new Item("music", "Music Page", "demo handling of edge cases of page naming"),
@@ -271,5 +273,10 @@
Object onActionFromSecurePage()
{
return _securePage.initialize("Triggered from Start");
+ }
+
+ public List getDemoContext()
+ {
+ return Arrays.asList(1, 2, 3);
}
}