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