Updated Branches:
  refs/heads/master a32faa924 -> a88b5f4cc

TAP5-2045: Set default CSS class for Label component to be "control-label", but 
allow overrides


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/a88b5f4c
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/a88b5f4c
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/a88b5f4c

Branch: refs/heads/master
Commit: a88b5f4cc0f62e89bac8e7feef3d2875a290aa24
Parents: a32faa9
Author: Howard M. Lewis Ship <[email protected]>
Authored: Wed Jul 24 16:34:08 2013 -0700
Committer: Howard M. Lewis Ship <[email protected]>
Committed: Wed Jul 24 16:34:08 2013 -0700

----------------------------------------------------------------------
 .../tapestry5/corelib/components/Label.java     | 16 +++++---
 tapestry-core/src/test/app1/DateFieldDemo.tml   | 26 ++++++-------
 .../tapestry5/integration/app1/MiscTests.groovy | 13 +++++++
 .../integration/app1/pages/DateFieldDemo.java   | 39 +++++++-------------
 .../tapestry5/integration/app1/pages/Index.java |  2 +
 .../app1/pages/OverrideLabelClassDemo.java      | 27 ++++++++++++++
 .../app1/pages/OverrideLabelClassDemo.tml       | 18 +++++++++
 7 files changed, 97 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a88b5f4c/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Label.java
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Label.java
 
b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Label.java
index 828b06b..f88b7e1 100644
--- 
a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Label.java
+++ 
b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Label.java
@@ -24,8 +24,7 @@ import org.apache.tapestry5.ioc.annotations.Inject;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 
 /**
- * Generates a &lt;label&gt; element for a particular field. It writes the CSS 
class "control-label", unless
- * an informal parameter writes a class attribute.
+ * Generates a &lt;label&gt; element for a particular field. It writes the CSS 
class "control-label".
  * <p/>
  * A Label will render its body, if it has one. However, in most cases it will 
not have a body, and will render its
  * {@linkplain org.apache.tapestry5.Field#getLabel() field's label} as it's 
body. Remember, however, that it is the
@@ -61,16 +60,23 @@ public class Label
 
     private Element labelElement;
 
+    /**
+     * CSS class name(s) for the Label.
+     *
+     * @since 5.4
+     */
+    @Parameter(name = "class", defaultPrefix = BindingConstants.LITERAL, value 
= "control-label")
+    private String className;
+
+
     boolean beginRender(MarkupWriter writer)
     {
         decorator.beforeLabel(field);
 
-        labelElement = writer.element("label");
+        labelElement = writer.element("label", "class", className);
 
         resources.renderInformalParameters(writer);
 
-        writer.attributes("class", "control-label");
-
         // 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.

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a88b5f4c/tapestry-core/src/test/app1/DateFieldDemo.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/app1/DateFieldDemo.tml 
b/tapestry-core/src/test/app1/DateFieldDemo.tml
index b26f872..e8544ca 100644
--- a/tapestry-core/src/test/app1/DateFieldDemo.tml
+++ b/tapestry-core/src/test/app1/DateFieldDemo.tml
@@ -35,20 +35,18 @@
 
 </div>
 
-<t:if test="birthday">
-    <hr/>
-
-    <dl>
-        <dt>Birthday</dt>
-        <dd id="birthday-output">
-            <t:output value="birthday" format="dateFormat"/>
-        </dd>
-        <dt>Impact</dt>
-        <dd id="impact-output">
-            <t:output value="asteroidImpact" format="dateFormat"/>
-        </dd>
-    </dl>
-</t:if>
+<hr/>
+
+<dl>
+    <dt>Birthday</dt>
+    <dd id="birthday-output">
+        <t:output value="birthday" format="dateFormat"/>
+    </dd>
+    <dt>Impact</dt>
+    <dd id="impact-output">
+        <t:output value="asteroidImpact" format="dateFormat"/>
+    </dd>
+</dl>
 
 
 </html>

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a88b5f4c/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/MiscTests.groovy
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/MiscTests.groovy
 
b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/MiscTests.groovy
index e57ae5a..d7ca9f9 100644
--- 
a/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/MiscTests.groovy
+++ 
b/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/MiscTests.groovy
@@ -32,4 +32,17 @@ class MiscTests extends TapestryCoreTestCase {
 
         // Using Geb, we could do a lot more. Sigh.
     }
+
+    // TAP5-2045
+    @Test
+    void label_class_override()
+    {
+        openLinks "Override Label Class Demo"
+
+        assertSourcePresent "<label for=\"firstName\" 
class=\"control-label\">First Name</label>",
+                            "<label for=\"lastName\" 
class=\"dummyClassName\">Last Name</label>"
+
+    }
+
+
 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a88b5f4c/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DateFieldDemo.java
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DateFieldDemo.java
 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DateFieldDemo.java
index d1adce0..0b628b2 100644
--- 
a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DateFieldDemo.java
+++ 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DateFieldDemo.java
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008 The Apache Software Foundation
+// Copyright 2007, 2008, 2013 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.
@@ -15,8 +15,8 @@
 package org.apache.tapestry5.integration.app1.pages;
 
 import org.apache.tapestry5.annotations.Persist;
+import org.apache.tapestry5.annotations.Property;
 import org.apache.tapestry5.beaneditor.Validate;
-import org.apache.tapestry5.corelib.components.DateField;
 import org.apache.tapestry5.ioc.annotations.Inject;
 import org.apache.tapestry5.services.PersistentLocale;
 
@@ -28,41 +28,24 @@ import java.util.Locale;
 public class DateFieldDemo
 {
     @Persist
+    @Property
+    @Validate("required")
     private Date birthday;
 
     @Persist
+    @Property
+    @Validate("required")
     private Date asteroidImpact;
 
     @Inject
     private PersistentLocale persistentLocale;
 
-    @Validate("required")
-    public Date getBirthday()
-    {
-        return birthday;
-    }
-
-    public void setBirthday(Date birthday)
-    {
-        this.birthday = birthday;
-    }
 
     public DateFormat getDateFormat()
     {
-        DateField df;
         return new SimpleDateFormat("MM/dd/yyyy");
     }
 
-    @Validate("required")
-    public Date getAsteroidImpact()
-    {
-        return asteroidImpact;
-    }
-
-    public void setAsteroidImpact(Date asteroidImpact)
-    {
-        this.asteroidImpact = asteroidImpact;
-    }
 
     void onActionFromClear()
     {
@@ -70,7 +53,13 @@ public class DateFieldDemo
         asteroidImpact = null;
     }
 
-    void onActionFromEnglish() { persistentLocale.set(Locale.ENGLISH); }
+    void onActionFromEnglish()
+    {
+        persistentLocale.set(Locale.ENGLISH);
+    }
 
-    void onActionFromFrench() { persistentLocale.set(Locale.FRENCH); }
+    void onActionFromFrench()
+    {
+        persistentLocale.set(Locale.FRENCH);
+    }
 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a88b5f4c/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
index 5f575e4..2142991 100644
--- 
a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
+++ 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
@@ -516,6 +516,8 @@ public class Index
 
                     new Item("OverrideFieldFocusDemo", "OverrideFieldFocus 
Demo", "Setting the focus in a form to a specific field"),
 
+                    new Item("OverrideLabelClassDemo", "Override Label Class 
Demo", "Setting class attribute on Label component"),
+
                     new Item("FormLinkParameters", "FormLinkParameters Demo", 
"Form link parameters should be unescaped for a hidden field")
             );
 

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a88b5f4c/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/OverrideLabelClassDemo.java
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/OverrideLabelClassDemo.java
 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/OverrideLabelClassDemo.java
new file mode 100644
index 0000000..93884bb
--- /dev/null
+++ 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/OverrideLabelClassDemo.java
@@ -0,0 +1,27 @@
+// Copyright 2013 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.annotations.Property;
+
+public class OverrideLabelClassDemo 
+{
+    @Property
+    private String firstName; 
+
+    @Property
+    private String lastName; 
+
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/a88b5f4c/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/OverrideLabelClassDemo.tml
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/OverrideLabelClassDemo.tml
 
b/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/OverrideLabelClassDemo.tml
new file mode 100644
index 0000000..bba4c18
--- /dev/null
+++ 
b/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/OverrideLabelClassDemo.tml
@@ -0,0 +1,18 @@
+<html t:type="Border" 
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd";>
+
+    <h1>Override Label Class</h1>
+
+    <p>
+        Demonstrates how to override the default class for a label by simply 
supplying a class attribute. 
+    </p>
+
+    <t:form>
+       <t:label for="firstName"/>
+       <t:textfield t:id="firstName"/>
+       
+       <t:label for="lastName" class="dummyClassName"/>
+       <t:textfield t:id="lastName"/>
+      
+    </t:form>
+
+</html>

Reply via email to