Author: hlship
Date: Thu Jan 24 10:26:58 2008
New Revision: 614954
URL: http://svn.apache.org/viewvc?rev=614954&view=rev
Log:
TAPESTRY-1642: When the Label component has a body, it should render that
rather than using the field's label
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Label.java
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BeanEditorOverride.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/SimpleForm.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Label.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Label.java?rev=614954&r1=614953&r2=614954&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Label.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/corelib/components/Label.java
Thu Jan 24 10:26:58 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -21,10 +21,16 @@
import org.apache.tapestry.annotations.*;
import org.apache.tapestry.dom.Element;
import org.apache.tapestry.ioc.annotations.Inject;
+import org.apache.tapestry.ioc.internal.util.InternalUtils;
import org.apache.tapestry.services.Heartbeat;
/**
* Generates a <label> element for a particular field.
+ * <p/>
+ * <p/>
+ * A Label will render its body, if it has one. However, in most cases it
will not have a body, and will render it's
+ * [EMAIL PROTECTED] org.apache.tapestry.Field#getLabel()} field's label} as
it's body. Remember, however, that it is the
+ * field label that will be used in any error messages.
*/
@SupportsInformalParameters
public class Label
@@ -45,6 +51,8 @@
@Inject
private ComponentResources _resources;
+ private Element _labelElement;
+
@BeginRender
void begin(MarkupWriter writer)
{
@@ -52,12 +60,12 @@
_decorator.beforeLabel(field);
- final Element element = writer.element("label");
+ _labelElement = writer.element("label");
_resources.renderInformalParameters(writer);
- // Since we don't know if the field has rendered yet, we need to defer
writing the for
- // attribute until we know the field has rendered (and set its
clientId property). That's
+ // Since we don't know if the field has rendered yet, we need to defer
writing the for and id
+ // attributes until we know the field has rendered (and set its
clientId property). That's
// exactly what Heartbeat is for.
Runnable command = new Runnable()
@@ -66,27 +74,24 @@
{
String fieldId = field.getClientId();
- element.forceAttributes("for", fieldId, "id", fieldId +
":label");
+ _labelElement.forceAttributes("for", fieldId, "id", fieldId +
":label");
- _decorator.insideLabel(field, element);
+ _decorator.insideLabel(field, _labelElement);
}
};
_heartbeat.defer(command);
}
- @BeforeRenderBody
- boolean renderBody()
- {
- // Don't render the body of the component even if there is one.
-
- return false;
- }
-
@AfterRender
void after(MarkupWriter writer)
{
- writer.write(_field.getLabel());
+ // If the Label element has a body that renders some non-blank output,
that takes precendence
+ // over the label string provided by the field.
+
+ boolean bodyIsBlank =
InternalUtils.isBlank(_labelElement.getChildMarkup());
+
+ if (bodyIsBlank) writer.write(_field.getLabel());
writer.end(); // label
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BeanEditorOverride.tml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BeanEditorOverride.tml?rev=614954&r1=614953&r2=614954&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BeanEditorOverride.tml
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BeanEditorOverride.tml
Thu Jan 24 10:26:58 2008
@@ -5,7 +5,7 @@
<p>Demonstrates that the BeanEditor properly supports overrides of its
property editors.</p>
- <t:form>
+ <form t:id="form">
<t:errors/>
<div class="t-beaneditor">
@@ -19,7 +19,7 @@
</div>
<input type="submit" value="Register"/>
- </t:form>
+ </form>
<p>[<t:actionlink t:id="clear">Clear Data</t:actionlink>]
</p>
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/SimpleForm.tml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/SimpleForm.tml?rev=614954&r1=614953&r2=614954&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/SimpleForm.tml
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/SimpleForm.tml Thu Jan
24 10:26:58 2008
@@ -1,48 +1,51 @@
-<html t:type="Border"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
- <h1>Simple Form</h1>
-
- <p> This is the <em>very early</em> start to Tapestry 5 form support. </p>
-
- <t:form>
- <input t:type="Checkbox" t:id="disabled"/>
- <t:label for="disabled"/>
- <br/>
-
- <div class="t-beaneditor">
-
- <t:label for="email">This isn't used</t:label>
- <input t:type="TextField" t:id="email" value="incident.email" size="50"
disabled="disabled"/>
- <br/>
- <t:label for="message"/>
- <input t:type="TextArea" t:id="message" label="Incident Message"
value="incident.message"
- cols="50" rows="10" disabled="disabled"> You can put text here, but it
isn't used. </input>
- <br/>
- <t:label for="operatingSystem"/>
- <select t:type="Select" t:id="operatingSystem"
value="incident.operatingSystem"
- model="message:os-values" disabled="disabled"/>
- <br/>
- <t:label for="department"/>
- <select t:type="Select" t:id="department" value="incident.department"
disabled="disabled"/>
- <br/>
- <t:label for="urgent"/>
- <input t:type="Checkbox" t:id="urgent" value="incident.urgent"
disabled="disabled"/>
- <br/>
- <input type="submit"/>
- </div>
- </t:form>
-
- <hr/>
-
- <p> Entered data: </p>
-
- <ul>
- <li>email: [${incident.email}]</li>
- <li>message: [${incident.message}]</li>
- <li>OS: [${incident.operatingSystem}]</li>
- <li>urgent: [${incident.urgent}]</li>
- <li>department: [${incident.department}]</li>
- </ul>
+<html t:type="Border"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+ <h1>Simple Form</h1>
+ <p>This is the
+ <em>very early</em>
+ start to Tapestry 5 form support.
+ </p>
+
+ <t:form>
+ <input t:type="Checkbox" t:id="disabled"/>
+ <t:label for="disabled"/>
+ <br/>
+
+ <div class="t-beaneditor">
+
+ <t:label for="email">User Email</t:label>
+ <input t:type="TextField" t:id="email" value="incident.email"
size="50" disabled="disabled"/>
+ <br/>
+ <t:label for="message"/>
+ <input t:type="TextArea" t:id="message" label="Incident Message"
value="incident.message"
+ cols="50" rows="10" disabled="disabled">You can put text
here, but it isn't used.
+ </input>
+ <br/>
+ <t:label for="operatingSystem"/>
+ <select t:type="Select" t:id="operatingSystem"
value="incident.operatingSystem"
+ model="message:os-values" disabled="disabled"/>
+ <br/>
+ <t:label for="department"/>
+ <select t:type="Select" t:id="department"
value="incident.department" disabled="disabled"/>
+ <br/>
+ <t:label for="urgent"/>
+ <input t:type="Checkbox" t:id="urgent" value="incident.urgent"
disabled="disabled"/>
+ <br/>
+ <input type="submit"/>
+ </div>
+ </t:form>
+
+ <hr/>
+
+ <p>Entered data:</p>
+
+ <ul>
+ <li>email: [${incident.email}]</li>
+ <li>message: [${incident.message}]</li>
+ <li>OS: [${incident.operatingSystem}]</li>
+ <li>urgent: [${incident.urgent}]</li>
+ <li>department: [${incident.department}]</li>
+ </ul>
</html>
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java?rev=614954&r1=614953&r2=614954&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
Thu Jan 24 10:26:58 2008
@@ -377,7 +377,10 @@
start("SimpleForm");
assertText("//[EMAIL PROTECTED]'disabled:label']", "Disabled");
- assertText("//[EMAIL PROTECTED]'email:label']", "Email");
+
+ // This demonstrates TAPESTRY-1642:
+ assertText("//[EMAIL PROTECTED]'email:label']", "User Email");
+
assertText("//[EMAIL PROTECTED]'message:label']", "Incident Message");
assertText("//[EMAIL PROTECTED]'operatingSystem:label']", "Operating
System");
assertText("//[EMAIL PROTECTED]'department:label']", "Department");
@@ -513,9 +516,6 @@
{
start("BeanEditor Demo", "Clear Data");
clickAndWait(SUBMIT);
-
- assertTextPresent("(First Name is Required)", "You must provide a
value for First Name.",
- "Everyone has to have a last name!", "Year of Birth
requires a value of at least 1900.");
// Part of the override for the firstName property