From cb9b2e56aeddbb082ec522c76a1240c830f4b7e6 Mon Sep 17 00:00:00 2001 From: Musachy Barroso Date: Mon, 9 Mar 2009 19:28:20 +0000 Subject: [PATCH] WW-3029 Fix backward compatible problem in the Label tag git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@751799 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/struts2/components/Label.java | 9 ++++--- .../struts2/views/jsp/ui/LabelTest.java | 27 ++++++++++++++++--- .../apache/struts2/views/jsp/ui/Label-2.txt | 4 +-- .../apache/struts2/views/jsp/ui/Label-4.txt | 4 +++ .../apache/struts2/views/jsp/ui/Label-5.txt | 4 +++ 5 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 core/src/test/resources/org/apache/struts2/views/jsp/ui/Label-4.txt create mode 100644 core/src/test/resources/org/apache/struts2/views/jsp/ui/Label-5.txt diff --git a/core/src/main/java/org/apache/struts2/components/Label.java b/core/src/main/java/org/apache/struts2/components/Label.java index 926cedbdf..9a162f71e 100644 --- a/core/src/main/java/org/apache/struts2/components/Label.java +++ b/core/src/main/java/org/apache/struts2/components/Label.java @@ -84,9 +84,12 @@ public class Label extends UIBean { if (value != null) { addParameter("nameValue", findString(value)); } else if (key != null) { - // get the label from a TextProvider (default value is the key) - String providedLabel = TextProviderHelper.getText(key, key, stack); - addParameter("nameValue", providedLabel); + Object nameValue = parameters.get("nameValue"); + if (nameValue == null || nameValue.toString().length() == 0) { + // get the label from a TextProvider (default value is the key) + String providedLabel = TextProviderHelper.getText(key, key, stack); + addParameter("nameValue", providedLabel); + } } else if (name != null) { String expr = completeExpressionIfAltSyntax(name); addParameter("nameValue", findString(expr)); diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ui/LabelTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ui/LabelTest.java index 98dadeaab..e17d85716 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/ui/LabelTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/LabelTest.java @@ -97,7 +97,7 @@ public class LabelTest extends AbstractUITagTest { tag.doStartTag(); tag.doEndTag(); - verify(LabelTest.class.getResource("Label-2.txt")); + verify(LabelTest.class.getResource("Label-5.txt")); } public void testGenericSimple() throws Exception { @@ -110,7 +110,7 @@ public class LabelTest extends AbstractUITagTest { verifyGenericProperties(tag, "xhtml", null); } - public void testWithKey() throws Exception { + public void testWithKeyNoValueFromStack() throws Exception { TestAction testAction = (TestAction) action; final String key = "labelKey"; final String value = "baz"; @@ -122,7 +122,7 @@ public class LabelTest extends AbstractUITagTest { tag.setPageContext(pageContext); tag.setLabel("mylabel"); tag.setFor("for"); - tag.setName("foo"); + tag.setName("foo2"); tag.setKey(key); tag.doStartTag(); @@ -131,4 +131,25 @@ public class LabelTest extends AbstractUITagTest { verify(LabelTest.class.getResource("Label-2.txt")); } + public void testWithKeyValueFromStack() throws Exception { + TestAction testAction = (TestAction) action; + final String key = "labelKey"; + final String value = "baz"; + testAction.setText(key, value); + + testAction.setFoo("output"); + + LabelTag tag = new LabelTag(); + tag.setPageContext(pageContext); + tag.setLabel("mylabel"); + tag.setFor("for"); + tag.setName("foo"); + tag.setKey(key); + + tag.doStartTag(); + tag.doEndTag(); + + verify(LabelTest.class.getResource("Label-4.txt")); + } + } diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Label-2.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Label-2.txt index 81faa6466..f4859443c 100644 --- a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Label-2.txt +++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Label-2.txt @@ -1,4 +1,4 @@ - - + + diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Label-4.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Label-4.txt new file mode 100644 index 000000000..b190ae523 --- /dev/null +++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Label-4.txt @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Label-5.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Label-5.txt new file mode 100644 index 000000000..17addde78 --- /dev/null +++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Label-5.txt @@ -0,0 +1,4 @@ + + + + \ No newline at end of file