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
This commit is contained in:
Musachy Barroso
2009-03-09 19:28:20 +00:00
parent 64470c7357
commit cb9b2e56ae
5 changed files with 40 additions and 8 deletions
@@ -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));
@@ -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"));
}
}
@@ -1,4 +1,4 @@
<tr>
<td class="tdLabel"><label for="foo" class="label">mylabel:</label></td>
<td><label id="foo" for="for">baz</label></td>
<td class="tdLabel"><label for="foo2" class="label">mylabel:</label></td>
<td><label id="foo2" for="for">baz</label></td>
</tr>
@@ -0,0 +1,4 @@
<tr>
<td class="tdLabel"><label for="foo" class="label">mylabel:</label></td>
<td><label id="foo" for="for">output</label></td>
</tr>
@@ -0,0 +1,4 @@
<tr>
<td class="tdLabel"><label for="foo" class="label">mylabel:</label></td>
<td><label id="foo" for="for">baz</label></td>
</tr>