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 2011/04/01 02:58:38 UTC
svn commit: r1087532 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry5/internal/bindings/
main/java/org/apache/tapestry5/internal/structure/
main/resources/org/apache/tapestry5/internal/structure/
test/java/org/apache/tap...
Author: hlship
Date: Fri Apr 1 00:58:37 2011
New Revision: 1087532
URL: http://svn.apache.org/viewvc?rev=1087532&view=rev
Log:
TAP5-35: During an Ajax update, using a "var:" binding prefix causes an exception indicating that the page is not rendering
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/bindings/RenderVariableBinding.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/StructureMessages.java
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/internal/structure/StructureStrings.properties
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImplTest.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/bindings/RenderVariableBinding.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/bindings/RenderVariableBinding.java?rev=1087532&r1=1087531&r2=1087532&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/bindings/RenderVariableBinding.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/bindings/RenderVariableBinding.java Fri Apr 1 00:58:37 2011
@@ -1,10 +1,10 @@
-// Copyright 2008, 2009 The Apache Software Foundation
+// Copyright 2008, 2009, 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
+// 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,
@@ -23,8 +23,7 @@ public class RenderVariableBinding exten
private final ComponentResources resources;
private final String name;
- public RenderVariableBinding(Location location, String description, ComponentResources resources, String name
- )
+ public RenderVariableBinding(Location location, String description, ComponentResources resources, String name)
{
super(location);
@@ -54,7 +53,6 @@ public class RenderVariableBinding exten
return String.format("RenderVariable[%s %s]", description, name);
}
-
public Object get()
{
return resources.getRenderVariable(name);
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java?rev=1087532&r1=1087531&r2=1087532&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java Fri Apr 1 00:58:37 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2009, 2010 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009, 2010, 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.
@@ -461,14 +461,19 @@ public class InternalComponentResourcesI
return result;
}
- private synchronized Map<String, Object> getRenderVariables()
+ private synchronized Map<String, Object> getRenderVariables(boolean create)
{
if (renderVariables == null)
+ {
+ if (!create)
+ return null;
+
renderVariables = elementResources.createPerThreadValue();
+ }
Map<String, Object> result = renderVariables.get();
- if (result == null)
+ if (result == null && create)
result = renderVariables.set(CollectionFactory.newCaseInsensitiveMap());
return result;
@@ -476,13 +481,13 @@ public class InternalComponentResourcesI
public Object getRenderVariable(String name)
{
- Map<String, Object> renderVariables = getRenderVariables();
+ Map<String, Object> variablesMap = getRenderVariables(false);
- Object result = InternalUtils.get(renderVariables, name);
+ Object result = InternalUtils.get(variablesMap, name);
if (result == null)
throw new IllegalArgumentException(StructureMessages.missingRenderVariable(getCompleteId(), name,
- renderVariables == null ? null : renderVariables.keySet()));
+ variablesMap == null ? null : variablesMap.keySet()));
return result;
}
@@ -491,17 +496,18 @@ public class InternalComponentResourcesI
{
assert InternalUtils.isNonBlank(name);
assert value != null;
- if (!element.isRendering())
- throw new IllegalStateException(StructureMessages.renderVariableSetWhenNotRendering(getCompleteId(), name));
- Map<String, Object> renderVariables = getRenderVariables();
+ Map<String, Object> renderVariables = getRenderVariables(true);
renderVariables.put(name, value);
}
public void postRenderCleanup()
{
- getRenderVariables().clear();
+ Map<String, Object> variablesMap = getRenderVariables(false);
+
+ if (variablesMap != null)
+ variablesMap.clear();
}
public void addPageLifecycleListener(PageLifecycleListener listener)
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/StructureMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/StructureMessages.java?rev=1087532&r1=1087531&r2=1087532&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/StructureMessages.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/StructureMessages.java Fri Apr 1 00:58:37 2011
@@ -1,10 +1,10 @@
-// Copyright 2006, 2007, 2008, 2009 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009, 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
+// 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,
@@ -14,16 +14,13 @@
package org.apache.tapestry5.internal.structure;
+import java.util.Collection;
+import java.util.List;
+
import org.apache.tapestry5.ioc.Location;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.apache.tapestry5.ioc.internal.util.MessagesImpl;
-import org.apache.tapestry5.ComponentResources;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-import java.util.Arrays;
final class StructureMessages
{
@@ -38,7 +35,7 @@ final class StructureMessages
return MESSAGES.format("missing-parameters", InternalUtils.joinSorted(parameters), element
.getComponentResources().getComponentModel().getComponentClassName());
}
-
+
static String unknownMixin(String componentId, String mixinClassName)
{
return MESSAGES.format("unknown-mixin", componentId, mixinClassName);
@@ -71,8 +68,8 @@ final class StructureMessages
static String originalChildComponent(ComponentPageElement container, String childId, Location originalLocation)
{
- return MESSAGES.format("original-child-component", container.getCompleteId(), childId,
- originalLocation.getResource().getPath(), originalLocation.getLine());
+ return MESSAGES.format("original-child-component", container.getCompleteId(), childId, originalLocation
+ .getResource().getPath(), originalLocation.getLine());
}
static String duplicateBlock(ComponentPageElement component, String blockId)
@@ -91,11 +88,6 @@ final class StructureMessages
return MESSAGES.format("missing-render-variable", componentId, name, InternalUtils.joinSorted(names));
}
- static String renderVariableSetWhenNotRendering(String completeId, String name)
- {
- return MESSAGES.format("render-variable-set-when-not-rendering", completeId, name);
- }
-
static String persistChangeBeforeLoadComplete()
{
return MESSAGES.get("persist-change-before-load-complete");
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/internal/structure/StructureStrings.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/internal/structure/StructureStrings.properties?rev=1087532&r1=1087531&r2=1087532&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/internal/structure/StructureStrings.properties (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/internal/structure/StructureStrings.properties Fri Apr 1 00:58:37 2011
@@ -28,6 +28,5 @@ duplicate-block=Component %s already con
Block ids must be unique (excluding case, which is ignored).
field-persist-failure=Error persisting field %s:%s: %s
missing-render-variable=Component %s does not contain a stored render variable with name '%s'. Stored render variables: %s.
-render-variable-set-when-not-rendering=Component %s is not rendering, so render variable '%s' may not be updated.
persist-change-before-load-complete=Persistent fields may not be updated until after the page has finished loading. \
This may be due to a persistent field with a default value. The default value should be removed.
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImplTest.java?rev=1087532&r1=1087531&r2=1087532&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImplTest.java Fri Apr 1 00:58:37 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2010 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2010, 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.
@@ -139,17 +139,14 @@ public class InternalComponentResourcesI
Component component = mockComponent();
Instantiator ins = mockInstantiator(component);
ComponentModel model = mockComponentModel();
- ComponentPageElement element = mockComponentPageElement();
Object value = new Object();
train_getModel(ins, model);
- train_isRendering(element, true);
-
replay();
- ComponentResources resources = new InternalComponentResourcesImpl(null, element, null, elementResources, "id",
+ ComponentResources resources = new InternalComponentResourcesImpl(null, null, null, elementResources, "id",
null, ins, false);
resources.storeRenderVariable("myRenderVar", value);