WW-2171 "Label tag does not use key attribute to lookup value in resources when using simple theme" Apply patch provided by Maja S Bratseth.

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@614842 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ted Nathan Husted
2008-01-24 11:09:59 +00:00
parent 09147ffad2
commit 613f786d91
3 changed files with 40 additions and 6 deletions
@@ -78,15 +78,17 @@ public class Label extends UIBean {
addParameter("for", findString(forAttr));
}
// try value first, then name (this overrides the default behavior in the superclass)
// try value, then key, then name (this overrides the default behavior in the superclass)
if (value != null) {
addParameter("nameValue", findString(value));
} else if (key != null) {
String expr = "%{getText('"+ key +"')}";
addParameter("nameValue", findString(expr));
} else if (name != null) {
String expr = name;
if (altSyntax()) {
expr = "%{" + expr + "}";
}
addParameter("nameValue", findString(expr));
}
}
@@ -20,10 +20,7 @@
*/
package org.apache.struts2;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.*;
import org.apache.struts2.views.jsp.ui.User;
@@ -50,6 +47,19 @@ public class TestAction extends ActionSupport {
private List list3;
private SomeEnum status = SomeEnum.COMPLETED;
private final Map texts = new HashMap();
public void setText(String key, String value) {
this.texts.put(key, value);
}
public String getText(String key) {
if (this.texts.containsKey(key)) {
return (String) this.texts.get(key);
}
return super.getText(key);
}
public Collection getCollection() {
return collection;
}
@@ -108,4 +108,26 @@ public class LabelTest extends AbstractUITagTest {
LabelTag tag = new LabelTag();
verifyGenericProperties(tag, "xhtml", null);
}
public void testWithKey() throws Exception {
TestAction testAction = (TestAction) action;
final String key = "labelKey";
final String value = "baz";
testAction.setText(key, value);
testAction.setFoo("notToBeOutput");
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-2.txt"));
}
}