You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2010/03/27 21:24:07 UTC
svn commit: r928262 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry5/corelib/components/
main/java/org/apache/tapestry5/internal/services/
main/java/org/apache/tapestry5/services/
main/resources/org/apache/tapestry5/ tes...
Author: hlship
Date: Sat Mar 27 20:24:06 2010
New Revision: 928262
URL: http://svn.apache.org/viewvc?rev=928262&view=rev
Log:
TAP5-1084: Zones that initially render inside a Form should support updates within the Form
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ZoneFormUpdateDemo.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ZoneFormUpdateDemo.java (with props)
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneTests.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImplTest.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java?rev=928262&r1=928261&r2=928262&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Zone.java Sat Mar 27 20:24:06 2010
@@ -14,13 +14,18 @@
package org.apache.tapestry5.corelib.components;
-import org.apache.tapestry5.*;
+import org.apache.tapestry5.BindingConstants;
+import org.apache.tapestry5.Block;
+import org.apache.tapestry5.CSSClassConstants;
+import org.apache.tapestry5.ClientElement;
+import org.apache.tapestry5.ComponentResources;
+import org.apache.tapestry5.MarkupWriter;
+import org.apache.tapestry5.QueryParameterConstants;
import org.apache.tapestry5.annotations.Environmental;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.SupportsInformalParameters;
import org.apache.tapestry5.dom.Element;
import org.apache.tapestry5.ioc.annotations.Inject;
-import org.apache.tapestry5.json.JSONObject;
import org.apache.tapestry5.services.ClientBehaviorSupport;
import org.apache.tapestry5.services.Heartbeat;
import org.apache.tapestry5.services.javascript.JavascriptSupport;
@@ -135,11 +140,6 @@ public class Zone implements ClientEleme
if (!visible)
e.addClassName(CSSClassConstants.INVISIBLE);
- // And continue on to render the body
-
- JSONObject spec = new JSONObject();
- spec.put("div", clientId);
-
clientBehaviorSupport.addZone(clientId, show, update);
heartbeat.begin();
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImpl.java?rev=928262&r1=928261&r2=928262&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImpl.java Sat Mar 27 20:24:06 2010
@@ -20,17 +20,22 @@ import org.apache.tapestry5.corelib.data
import org.apache.tapestry5.json.JSONArray;
import org.apache.tapestry5.json.JSONObject;
import org.apache.tapestry5.services.ClientBehaviorSupport;
+import org.apache.tapestry5.services.Environment;
+import org.apache.tapestry5.services.FormSupport;
import org.apache.tapestry5.services.javascript.JavascriptSupport;
public class ClientBehaviorSupportImpl implements ClientBehaviorSupport
{
private final JavascriptSupport javascriptSupport;
+ private final Environment environment;
+
private final JSONObject validations = new JSONObject();
- public ClientBehaviorSupportImpl(JavascriptSupport javascriptSupport)
+ public ClientBehaviorSupportImpl(JavascriptSupport javascriptSupport, Environment environment)
{
this.javascriptSupport = javascriptSupport;
+ this.environment = environment;
}
public void addZone(String clientId, String showFunctionName, String updateFunctionName)
@@ -40,6 +45,15 @@ public class ClientBehaviorSupportImpl i
addFunction(spec, "show", showFunctionName);
addFunction(spec, "update", updateFunctionName);
+ FormSupport formSupport = environment.peek(FormSupport.class);
+
+ if (formSupport != null)
+ {
+ JSONObject parameters = new JSONObject(RequestConstants.FORM_CLIENTID_PARAMETER, formSupport.getClientId(),
+ RequestConstants.FORM_COMPONENTID_PARAMETER, formSupport.getFormComponentId());
+ spec.put("parameters", parameters);
+ }
+
javascriptSupport.addInitializerCall("zone", spec);
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=928262&r1=928261&r2=928262&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java Sat Mar 27 20:24:06 2010
@@ -1976,7 +1976,8 @@ public final class TapestryModule
{
JavascriptSupport javascriptSupport = environment.peekRequired(JavascriptSupport.class);
- ClientBehaviorSupportImpl clientBehaviorSupport = new ClientBehaviorSupportImpl(javascriptSupport);
+ ClientBehaviorSupportImpl clientBehaviorSupport = new ClientBehaviorSupportImpl(javascriptSupport,
+ environment);
environment.push(ClientBehaviorSupport.class, clientBehaviorSupport);
@@ -2123,7 +2124,7 @@ public final class TapestryModule
{
JavascriptSupport javascriptSupport = environment.peekRequired(JavascriptSupport.class);
- ClientBehaviorSupportImpl support = new ClientBehaviorSupportImpl(javascriptSupport);
+ ClientBehaviorSupportImpl support = new ClientBehaviorSupportImpl(javascriptSupport, environment);
environment.push(ClientBehaviorSupport.class, support);
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js?rev=928262&r1=928261&r2=928262&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js Sat Mar 27 20:24:06 2010
@@ -1494,6 +1494,7 @@ Tapestry.ZoneManager = Class.create( {
|| Tapestry.ElementEffect.show;
this.updateFunc = Tapestry.ElementEffect[spec.update]
|| Tapestry.ElementEffect.highlight;
+ this.specParameters = spec.parameters;
/*
* TAP5-707: store the old background color of the element or take white
@@ -1590,7 +1591,7 @@ Tapestry.ZoneManager = Class.create( {
var finalParameters = $H( {
"t:zoneid" : this.element.id
- });
+ }).update(this.specParameters);
/* If parameters were supplied, merge them in with the zone id */
if (!Object.isUndefined(parameters))
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ZoneFormUpdateDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ZoneFormUpdateDemo.tml?rev=928262&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ZoneFormUpdateDemo.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/ZoneFormUpdateDemo.tml Sat Mar 27 20:24:06 2010
@@ -0,0 +1,42 @@
+<html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
+
+ <h1>Zone/Form Update Demo</h1>
+
+ <h2>Form</h2>
+
+ <t:form t:id="form">
+
+ <t:zone t:id="zone" id="zone">
+
+ <p id="initial">
+ Initial content.
+ </p>
+
+ </t:zone>
+
+ <br/>
+ <input type="submit" value="Submit Form"/>
+
+ </t:form>
+
+ <p>
+ <t:actionlink t:id="update" zone="zone">Update the form</t:actionlink>
+ </p>
+
+ <h2>Data</h2>
+
+ <p>
+ Entered value:
+ <strong id="output">${value}</strong>
+ </p>
+
+ <t:block id="fields">
+
+ <p id="updated">Updated content:</p>
+
+ <label for="value"/>
+ <t:textfield t:id="value"/>
+
+ </t:block>
+
+</html>
\ No newline at end of file
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneTests.java?rev=928262&r1=928261&r2=928262&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneTests.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneTests.java Sat Mar 27 20:24:06 2010
@@ -1,10 +1,10 @@
-// Copyright 2009 The Apache Software Foundation
+// Copyright 2009, 2010 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
+// 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,
@@ -42,8 +42,7 @@ public class ZoneTests extends TapestryC
waitForCondition(condition, PAGE_LOAD_TIMEOUT);
- assertText(String.format("//div[@class='%s']/span", "t-error-popup"),
- "You must provide a value for Car Model.");
+ assertText(String.format("//div[@class='%s']/span", "t-error-popup"), "You must provide a value for Car Model.");
type("carModel", "7 Series");
@@ -203,29 +202,46 @@ public class ZoneTests extends TapestryC
assertTextPresent(Form.class.getName() + "[form--form]");
}
-
+
/**
* TAP5-707
*/
-
+
@Test
public void zone_fade_back_backgroundcolor()
{
clickThru("Form Zone Demo");
-
+
type("longValue", "12");
-
+
click(SUBMIT);
-
+
click(SUBMIT);
-
+
// wait some time to let the fade go away
sleep(4050);
// will only work in firefox.
String color = getEval("selenium.browserbot.getCurrentWindow().getComputedStyle(this.page().findElement(\"xpath=//div[@id='valueZone']\"),'').getPropertyValue('background-color').toLowerCase()");
-
+
assertEquals(color, "rgb(255, 255, 255)");
}
+ /** TAP5-1084 */
+ @Test
+ public void update_zone_inside_form()
+ {
+ clickThru("Zone/Form Update Demo");
+
+ click("link=Update the form");
+
+ waitForElementToAppear("updated");
+
+ type("//INPUT[@type='text']", "Tapestry 5.2");
+
+ clickAndWait(SUBMIT);
+
+ assertText("output", "Tapestry 5.2");
+ }
+
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java?rev=928262&r1=928261&r2=928262&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java Sat Mar 27 20:24:06 2010
@@ -67,6 +67,8 @@ public class Index
private static final List<Item> ITEMS = CollectionFactory
.newList(
+ new Item("ZoneFormUpdateDemo", "Zone/Form Update Demo", "Updating a Zone inside a Form"),
+
new Item("RenderNotificationDemo", "RenderNotification Demo", "Use of RenderNotification mixin"),
new Item("InjectMessagesDemo", "Inject Global Messages into Service Demo",
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ZoneFormUpdateDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ZoneFormUpdateDemo.java?rev=928262&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ZoneFormUpdateDemo.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ZoneFormUpdateDemo.java Sat Mar 27 20:24:06 2010
@@ -0,0 +1,36 @@
+// Copyright 2010 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.Block;
+import org.apache.tapestry5.PersistenceConstants;
+import org.apache.tapestry5.annotations.Persist;
+import org.apache.tapestry5.annotations.Property;
+import org.apache.tapestry5.ioc.annotations.Inject;
+
+public class ZoneFormUpdateDemo
+{
+ @Property
+ @Persist(PersistenceConstants.FLASH)
+ private String value;
+
+ @Inject
+ private Block fields;
+
+ Object onActionFromUpdate()
+ {
+ return fields;
+ }
+}
Propchange: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ZoneFormUpdateDemo.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImplTest.java?rev=928262&r1=928261&r2=928262&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClientBehaviorSupportImplTest.java Sat Mar 27 20:24:06 2010
@@ -16,6 +16,8 @@ package org.apache.tapestry5.internal.se
import org.apache.tapestry5.Link;
import org.apache.tapestry5.json.JSONObject;
+import org.apache.tapestry5.services.Environment;
+import org.apache.tapestry5.services.FormSupport;
import org.apache.tapestry5.services.javascript.JavascriptSupport;
import org.apache.tapestry5.test.TapestryTestCase;
import org.testng.annotations.Test;
@@ -25,7 +27,7 @@ public class ClientBehaviorSupportImplTe
@Test
public void no_changes()
{
- ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(null);
+ ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(null, null);
setup.commit();
}
@@ -40,7 +42,7 @@ public class ClientBehaviorSupportImplTe
replay();
- ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(js);
+ ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(js, null);
setup.linkZone("client1", "zone1", link1);
@@ -53,13 +55,16 @@ public class ClientBehaviorSupportImplTe
public void add_zones()
{
JavascriptSupport js = mockJavascriptSupport();
+ Environment environment = mockEnvironment();
+
+ expect(environment.peek(FormSupport.class)).andReturn(null).atLeastOnce();
js.addInitializerCall("zone", new JSONObject("element", "client1"));
js.addInitializerCall("zone", new JSONObject("element", "client2"));
replay();
- ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(js);
+ ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(js, environment);
setup.addZone("client1", null, null);
setup.addZone("client2", null, null);
@@ -68,16 +73,46 @@ public class ClientBehaviorSupportImplTe
}
@Test
+ public void add_zone_inside_form()
+ {
+ JavascriptSupport js = mockJavascriptSupport();
+ Environment environment = mockEnvironment();
+ FormSupport fs = mockFormSupport();
+
+ expect(environment.peek(FormSupport.class)).andReturn(fs).atLeastOnce();
+
+ expect(fs.getClientId()).andReturn("myform");
+ expect(fs.getFormComponentId()).andReturn("MyPage.myform");
+
+ JSONObject expected = new JSONObject(String.format(
+ "{element:'client1', parameters:{'%s': 'myform', '%s': 'MyPage.myform' }}",
+ RequestConstants.FORM_CLIENTID_PARAMETER, RequestConstants.FORM_COMPONENTID_PARAMETER));
+
+ js.addInitializerCall("zone", expected);
+
+ replay();
+
+ ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(js, environment);
+
+ setup.addZone("client1", null, null);
+
+ verify();
+ }
+
+ @Test
public void zones_with_functions()
{
JavascriptSupport js = mockJavascriptSupport();
+ Environment environment = mockEnvironment();
+
+ expect(environment.peek(FormSupport.class)).andReturn(null).atLeastOnce();
js.addInitializerCall("zone", new JSONObject("{'element':'client1', 'show':'showme' }"));
js.addInitializerCall("zone", new JSONObject("{'element':'client2', 'update':'updateme' }"));
replay();
- ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(js);
+ ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(js, environment);
setup.addZone("client1", "showme", null);
setup.addZone("client2", null, "updateme");
@@ -89,13 +124,16 @@ public class ClientBehaviorSupportImplTe
public void zone_function_names_are_converted_to_lower_case()
{
JavascriptSupport js = mockJavascriptSupport();
+ Environment environment = mockEnvironment();
+
+ expect(environment.peek(FormSupport.class)).andReturn(null).atLeastOnce();
js.addInitializerCall("zone", new JSONObject("{'element':'client1', 'show':'showme' }"));
js.addInitializerCall("zone", new JSONObject("{'element':'client2', 'update':'updateme' }"));
replay();
- ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(js);
+ ClientBehaviorSupportImpl setup = new ClientBehaviorSupportImpl(js, environment);
setup.addZone("client1", "ShowMe", null);
setup.addZone("client2", null, "UpdateMe");