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 2009/01/23 19:30:18 UTC
svn commit: r737133 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry5/corelib/base/
main/java/org/apache/tapestry5/corelib/mixins/
main/java/org/apache/tapestry5/dom/
main/java/org/apache/tapestry5/internal/structure/ mai...
Author: hlship
Date: Fri Jan 23 10:30:17 2009
New Revision: 737133
URL: http://svn.apache.org/viewvc?rev=737133&view=rev
Log:
TAP5-402: BeanDisplay properties that render nothing cause layout errors (they should render a )
Added:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/NotEmpty.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ioc/
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ioc/internal/
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/ioc/internal/services/
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/ioc/
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/ioc/internal/
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/ioc/internal/services/
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/ioc/
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/ioc/internal/
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/ioc/internal/services/
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractPropertyOutput.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Text.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/transform/AbstractIncludeAssetWorker.java
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/BeanDisplay.tml
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridRows.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/dom/DOMTest.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractPropertyOutput.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractPropertyOutput.java?rev=737133&r1=737132&r2=737133&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractPropertyOutput.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractPropertyOutput.java Fri Jan 23 10:30:17 2009
@@ -117,15 +117,9 @@
Object value = readPropertyForObject();
- // TAPESTRY-2578: Write for null or merely blank.
-
String text = value == null ? "" : value.toString();
- if (InternalUtils.isBlank(text))
- {
- writer.writeRaw(" ");
- }
- else
+ if (InternalUtils.isNonBlank(text))
{
writer.write(text);
}
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/NotEmpty.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/NotEmpty.java?rev=737133&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/NotEmpty.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/NotEmpty.java Fri Jan 23 10:30:17 2009
@@ -0,0 +1,48 @@
+// Copyright 2009 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.corelib.mixins;
+
+import org.apache.tapestry5.MarkupWriter;
+import org.apache.tapestry5.annotations.MixinAfter;
+import org.apache.tapestry5.dom.Element;
+
+/**
+ * A mixin that attaches to an element that renders an element. At the end of the render, if the element is empty, then
+ * a non-breaking space ( ) is injected into the element. This is often necessary for proper rendering on the
+ * client.
+ * <p/>
+ * Often used in conjunction with the {@link org.apache.tapestry5.corelib.components.Any} component.
+ *
+ * @since 5.1.0.0
+ */
+@MixinAfter
+public class NotEmpty
+{
+ private Element element;
+
+ void beginRender(MarkupWriter writer)
+ {
+ element = writer.getElement();
+ }
+
+ void afterRender()
+ {
+ if (element.isEmpty())
+ {
+ element.removeChildren();
+ element.raw(" ");
+ }
+ }
+}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java?rev=737133&r1=737132&r2=737133&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Element.java Fri Jan 23 10:30:17 2009
@@ -654,4 +654,31 @@
return holder.getResult();
}
+
+ /**
+ * Returns true if the element has no children, or has only text children that contain only whitespace.
+ *
+ * @since 5.1.0.0
+ */
+ public boolean isEmpty()
+ {
+ List<Node> children = getChildren();
+
+ if (children.isEmpty()) return true;
+
+ for (Node n : children)
+ {
+ if (n instanceof Text)
+ {
+ Text t = (Text) n;
+
+ if (t.isEmpty()) continue;
+ }
+
+ // Not a text node, or a non-empty text node, then the element isn't empty.
+ return false;
+ }
+
+ return true;
+ }
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Text.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Text.java?rev=737133&r1=737132&r2=737133&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Text.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/dom/Text.java Fri Jan 23 10:30:17 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2008 The Apache Software Foundation
+// Copyright 2006, 2008, 2009 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.
@@ -33,6 +33,11 @@
write(text);
}
+ boolean isEmpty()
+ {
+ return buffer.length() == 0 || buffer.toString().trim().length() == 0;
+ }
+
/**
* Writes additional text into the node, appending it to any existing text.
*/
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=737133&r1=737132&r2=737133&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 Fri Jan 23 10:30:17 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009 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.
@@ -1016,7 +1016,7 @@
if (!renderPhasesInitalized)
initializeRenderPhases();
- // TODO: An error if the _render flag is already set (recursive rendering not
+ // TODO: An error if the render flag is already set (recursive rendering not
// allowed or advisable).
// Once we start rendering, the page is considered dirty, until we cleanup post render.
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/AbstractIncludeAssetWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/AbstractIncludeAssetWorker.java?rev=737133&r1=737132&r2=737133&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/AbstractIncludeAssetWorker.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/AbstractIncludeAssetWorker.java Fri Jan 23 10:30:17 2009
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008 The Apache Software Foundation
+// Copyright 2007, 2008, 2009 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.
@@ -18,6 +18,7 @@
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.internal.services.ComponentResourcesOperation;
+import org.apache.tapestry5.ioc.Resource;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.ioc.services.SymbolSource;
import org.apache.tapestry5.model.MutableComponentModel;
@@ -54,8 +55,9 @@
* @param assetPaths raw paths to be converted to assets
*/
protected final void addOperationForAssetPaths(ClassTransformation transformation,
- final MutableComponentModel model, String[] assetPaths)
+ MutableComponentModel model, String[] assetPaths)
{
+ final Resource baseResource = model.getBaseResource();
final List<String> paths = CollectionFactory.newList();
for (String value : assetPaths)
@@ -77,7 +79,7 @@
for (String assetPath : paths)
{
- Asset asset = assetSource.getAsset(model.getBaseResource(), assetPath, locale);
+ Asset asset = assetSource.getAsset(baseResource, assetPath, locale);
handleAsset(asset);
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/BeanDisplay.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/BeanDisplay.tml?rev=737133&r1=737132&r2=737133&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/BeanDisplay.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/BeanDisplay.tml Fri Jan 23 10:30:17 2009
@@ -5,7 +5,7 @@
<dt class="${propertyClass}">${propertyModel.label}</dt>
- <dd class="${propertyClass}">
+ <dd t:type="any" t:mixins="NotEmpty" class="${propertyClass}">
<t:propertydisplay model="propertyModel" overrides="overrides" object="object"/>
</dd>
</t:loop>
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridRows.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridRows.tml?rev=737133&r1=737132&r2=737133&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridRows.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/GridRows.tml Fri Jan 23 10:30:17 2009
@@ -1,6 +1,6 @@
<tr class="${rowClass}" xml:space="default" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<t:loop source="propertyNames" value="propertyName" index="columnIndex" volatile="inherit:volatile">
- <td class="${cellClass}">
+ <td class="${cellClass}" t:type="any" t:mixins="NotEmpty">
<t:gridcell model="columnModel" object="row" overrides="overrides"/>
</td>
</t:loop>
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/dom/DOMTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/dom/DOMTest.java?rev=737133&r1=737132&r2=737133&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/dom/DOMTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/dom/DOMTest.java Fri Jan 23 10:30:17 2009
@@ -683,4 +683,35 @@
assertEquals(d.toString(), "<doc><hr/><br/><img/></doc>");
}
+
+ /**
+ * TAP5-402
+ */
+ @Test
+ public void is_empty()
+ {
+ Document d = new Document();
+
+ Element root = d.newRootElement("root");
+
+ assertTrue(root.isEmpty());
+
+ root.text("");
+
+ assertTrue(root.isEmpty());
+
+ root.text(" ");
+
+ assertTrue(root.isEmpty());
+
+ Element child = root.element("child");
+
+ assertFalse(root.isEmpty());
+
+ assertTrue(child.isEmpty());
+
+ child.text("not empty");
+
+ assertFalse(child.isEmpty());
+ }
}