Repository: tapestry-5 Updated Branches: refs/heads/master 9f9658dfb -> a7f700c47
Closes TAP5-1658: If a Submit is used in a Grid, trigger the event with the context of the current iteration Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/a7f700c4 Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/a7f700c4 Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/a7f700c4 Branch: refs/heads/master Commit: a7f700c47e494f5227929481a82fb3ad675115f3 Parents: 9f9658d Author: Jochen Kemnade <jkemn...@apache.org> Authored: Thu May 29 11:53:37 2014 +0200 Committer: Jochen Kemnade <jkemn...@apache.org> Committed: Sat May 31 18:56:37 2014 +0200 ---------------------------------------------------------------------- .../tapestry5/corelib/components/Submit.java | 13 ++++- .../test/app1/GridWithSubmitWithContextDemo.tml | 16 ++++++ .../tapestry5/integration/app1/GridTests.java | 16 ++++++ .../pages/GridWithSubmitWithContextDemo.java | 60 ++++++++++++++++++++ .../tapestry5/integration/app1/pages/Index.java | 4 +- 5 files changed, 107 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a7f700c4/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Submit.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Submit.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Submit.java index e0f6fc7..efb1c88 100644 --- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Submit.java +++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Submit.java @@ -17,6 +17,7 @@ package org.apache.tapestry5.corelib.components; import org.apache.tapestry5.*; import org.apache.tapestry5.annotations.*; import org.apache.tapestry5.corelib.SubmitMode; +import org.apache.tapestry5.internal.util.Holder; import org.apache.tapestry5.ioc.annotations.Inject; import org.apache.tapestry5.ioc.internal.util.InternalUtils; import org.apache.tapestry5.json.JSONArray; @@ -194,12 +195,22 @@ public class Submit implements ClientElement if (disabled || !selected(clientId, elementName)) return; + // TAP5-1658: copy the context of the current Submit instance so we trigger the event with + // the correct context later + final Holder<Object[]> currentContextHolder = Holder.create(); + if (context != null) + { + Object[] currentContext = new Object[context.length]; + System.arraycopy(context, 0, currentContext, 0, context.length); + currentContextHolder.put(currentContext); + } + Runnable sendNotification = new Runnable() { public void run() { // TAP5-1024: allow for navigation result from the event callback - resources.triggerEvent(event, context, eventCallback); + resources.triggerEvent(event, currentContextHolder.get(), eventCallback); } }; http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a7f700c4/tapestry-core/src/test/app1/GridWithSubmitWithContextDemo.tml ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/app1/GridWithSubmitWithContextDemo.tml b/tapestry-core/src/test/app1/GridWithSubmitWithContextDemo.tml new file mode 100644 index 0000000..657028d --- /dev/null +++ b/tapestry-core/src/test/app1/GridWithSubmitWithContextDemo.tml @@ -0,0 +1,16 @@ +<html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"> + + <h1>Grid with Submit with context Demo</h1> + + <t:alerts /> + <t:form> + <table t:type="grid" t:id="grid" source="tracks" row="track" add="delete"> + <t:parameter name="ratingcell"> + <t:outputRating rating="track.rating"/> + </t:parameter> + <t:parameter name="deletecell"> + <t:submit class="btn" context="track"/> + </t:parameter> + </table> + </t:form> +</html> http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a7f700c4/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/GridTests.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/GridTests.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/GridTests.java index 2d5f7b3..f18f618 100644 --- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/GridTests.java +++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/GridTests.java @@ -351,5 +351,21 @@ public class GridTests extends App1TestCase } + /** + * TAP5-1658 + */ + @Test + public void submit_with_context_inside_grid() + { + openLinks("Grid with Submit with context"); + + clickAndWait("css=tr[data-grid-row='first'] input[type='submit']"); + assertTextPresent("Deleted Bug Juice"); + + clickAndWait("css=tr[data-grid-row='last'] input[type='submit']"); + assertTextPresent(" Deleted Studying Stones"); + + } + } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a7f700c4/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/GridWithSubmitWithContextDemo.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/GridWithSubmitWithContextDemo.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/GridWithSubmitWithContextDemo.java new file mode 100644 index 0000000..9d4a774 --- /dev/null +++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/GridWithSubmitWithContextDemo.java @@ -0,0 +1,60 @@ +// Copyright 2007, 2008, 2011 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.tapestry5.integration.app1.pages; + +import org.apache.tapestry5.alerts.AlertManager; +import org.apache.tapestry5.alerts.Duration; +import org.apache.tapestry5.alerts.Severity; +import org.apache.tapestry5.annotations.InjectComponent; +import org.apache.tapestry5.annotations.Property; +import org.apache.tapestry5.corelib.components.Grid; +import org.apache.tapestry5.func.F; +import org.apache.tapestry5.integration.app1.data.Track; +import org.apache.tapestry5.integration.app1.services.MusicLibrary; +import org.apache.tapestry5.ioc.annotations.Inject; + +import java.util.Comparator; + +public class GridWithSubmitWithContextDemo +{ + @Inject + private MusicLibrary library; + + @Inject + private AlertManager alertManager; + + @Property + private Track track; + + @InjectComponent + private Grid grid; + + public Iterable<Track> getTracks() + { + return F.flow(library.getTracks()).sort(new Comparator<Track>(){ + + @Override + public int compare(Track arg0, Track arg1) { + return arg0.getId().compareTo(arg1.getId()); + } + + }); + } + + void onSelected(Track track){ + alertManager.alert(Duration.SINGLE, Severity.INFO, "Deleted "+track.getTitle()); + } + +} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a7f700c4/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java ---------------------------------------------------------------------- diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java index bcaae7b..992bb34 100644 --- a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java +++ b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java @@ -570,7 +570,9 @@ public class Index new Item("GenericTypeDemo", "Generic bound type demo", "Tests that generic type info is available for generic bindings"), - new Item("FormFieldClientIdParameterDemo", "Form Field clientId Parameter Demo", "Shows and tests how to explicitly set the id of a form field component") + new Item("FormFieldClientIdParameterDemo", "Form Field clientId Parameter Demo", "Shows and tests how to explicitly set the id of a form field component"), + + new Item("gridwithsubmitwithcontextdemo", "Grid with Submit with context", "A grid whose rows contain a Submit component with context") ); static