Author: hlship
Date: Tue Sep 9 10:58:16 2008
New Revision: 693532
URL: http://svn.apache.org/viewvc?rev=693532&view=rev
Log:
TAPESTRY-2654: The Zone component should expose its body (as a Block) to make
it easier to re-render the Zone's body as an Ajax partial page render
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResourcesCommon.java
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/structure/ComponentPageElementImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/nested/ZoneDemo.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/ZoneDemo.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResourcesCommon.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResourcesCommon.java?rev=693532&r1=693531&r2=693532&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResourcesCommon.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ComponentResourcesCommon.java
Tue Sep 9 10:58:16 2008
@@ -149,4 +149,10 @@
* will return false.
*/
boolean hasBody();
+
+ /**
+ * Returns the body of this component as a (possibly empty) block. When
invoked on a mixin, returns the containing
+ * component's body.
+ */
+ Block getBody();
}
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=693532&r1=693531&r2=693532&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
Tue Sep 9 10:58:16 2008
@@ -110,4 +110,15 @@
{
return clientId;
}
+
+ /**
+ * Returns the zone's body (the content enclosed by its start and end
tags). This is often used as part of an Ajax
+ * partial page render to update the client with a fresh render of the
content inside the zone.
+ *
+ * @return the zone's body as a Block
+ */
+ public Block getBody()
+ {
+ return resources.getBody();
+ }
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java?rev=693532&r1=693531&r2=693532&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
Tue Sep 9 10:58:16 2008
@@ -50,6 +50,19 @@
public class ComponentPageElementImpl extends BaseLocatable implements
ComponentPageElement, PageLifecycleListener
{
/**
+ * Placeholder for the body used when the component has no real content.
+ */
+ private static class PlaceholderBlock implements Block, Renderable
+ {
+ public void render(MarkupWriter writer)
+ {
+ }
+ }
+
+ private static final Block PLACEHOLDER_BLOCK = new PlaceholderBlock();
+
+
+ /**
* @see #render(org.apache.tapestry5.MarkupWriter,
org.apache.tapestry5.runtime.RenderQueue)
*/
private static final RenderCommand POP_COMPONENT_ID = new RenderCommand()
@@ -277,7 +290,7 @@
queue.push(afterRenderBody);
- if (handler.getResult()) pushElements(queue, body);
+ if (handler.getResult() && bodyBlock != null)
queue.push(bodyBlock);
handler.queueCommands(queue);
}
@@ -357,7 +370,7 @@
private Map<String, Block> blocks;
- private List<PageElement> body;
+ private BlockImpl bodyBlock;
private Map<String, ComponentPageElement> children;
@@ -679,9 +692,9 @@
public void addToBody(PageElement element)
{
- if (body == null) body = CollectionFactory.newList();
+ if (bodyBlock == null) bodyBlock = new BlockImpl(getLocation());
- body.add(element);
+ bodyBlock.addToBody(element);
}
public void addToTemplate(PageElement element)
@@ -768,7 +781,7 @@
{
// If no body, then no beforeRenderBody or afterRenderBody
- if (body != null) queue.push(beforeRenderBody);
+ if (bodyBlock != null) queue.push(beforeRenderBody);
}
public String getCompleteId()
@@ -1178,7 +1191,12 @@
public boolean hasBody()
{
- return body != null;
+ return bodyBlock != null;
+ }
+
+ public Block getBody()
+ {
+ return bodyBlock == null ? PLACEHOLDER_BLOCK : bodyBlock;
}
public Map<String, Binding> getInformalParameterBindings()
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=693532&r1=693531&r2=693532&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
Tue Sep 9 10:58:16 2008
@@ -167,6 +167,11 @@
return null;
}
+ public Block getBody()
+ {
+ return element.getBody();
+ }
+
public boolean hasBody()
{
return element.hasBody();
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/nested/ZoneDemo.tml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/nested/ZoneDemo.tml?rev=693532&r1=693531&r2=693532&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/nested/ZoneDemo.tml
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/nested/ZoneDemo.tml
Tue Sep 9 10:58:16 2008
@@ -6,12 +6,9 @@
<t:zone t:id="output" style="float:right; width: 800px;"
update="slidedown">
- No name has been selected.
-
- <t:block id="showName">
+ <t:if test="name" else="No name has been selected.">
Selected: ${name}
- </t:block>
-
+ </t:if>
</t:zone>
<t:block id="registrationForm">
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/ZoneDemo.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/ZoneDemo.java?rev=693532&r1=693531&r2=693532&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/ZoneDemo.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/ZoneDemo.java
Tue Sep 9 10:58:16 2008
@@ -16,11 +16,9 @@
import org.apache.tapestry5.Block;
import org.apache.tapestry5.ValueEncoder;
-import org.apache.tapestry5.annotations.ApplicationState;
-import org.apache.tapestry5.annotations.Component;
-import org.apache.tapestry5.annotations.Log;
-import org.apache.tapestry5.annotations.Property;
+import org.apache.tapestry5.annotations.*;
import org.apache.tapestry5.corelib.components.BeanEditForm;
+import org.apache.tapestry5.corelib.components.Zone;
import org.apache.tapestry5.integration.app1.data.RegistrationData;
import org.apache.tapestry5.internal.services.StringValueEncoder;
import org.apache.tapestry5.ioc.annotations.Inject;
@@ -41,11 +39,15 @@
private static final String[] NAMES = {"Fred & Wilma", "Mr. <Roboto>",
"Grim Fandango", "Registration", "Vote"};
@Inject
- private Block showName, registrationForm, registrationOutput, voteForm,
voteOutput;
+ private Block registrationForm, registrationOutput, voteForm, voteOutput;
@Property
private String vote;
+ @InjectComponent
+ private Zone output;
+
+
public String[] getNames()
{
return NAMES;
@@ -71,7 +73,7 @@
if (name.equals("Vote")) return voteForm;
- return showName;
+ return output.getBody();
}
Object onSuccessFromRegistrationForm()