diff --git a/core/src/main/resources/template/simple/radiomap.ftl b/core/src/main/resources/template/simple/radiomap.ftl index cdff00ec0..b44a0be77 100644 --- a/core/src/main/resources/template/simple/radiomap.ftl +++ b/core/src/main/resources/template/simple/radiomap.ftl @@ -29,9 +29,12 @@ <#if parameters.listValueKey??> <#-- checks the valueStack for the 'valueKey.' The valueKey is then looked-up in the locale file for it's localized value. This is then used as a label --> - <#assign itemValue = stack.findString(parameters.listValueKey)/> - <#-- FIXME: find a better way to get the value than a call to @s.text --> - <#assign itemValue><@s.text name="${itemValue}"/> + <#assign valueKey = stack.findString(parameters.listValueKey)!''/> + <#if valueKey?has_content> + <#assign itemValue = struts.getText(valueKey) /> + <#else> + <#assign itemValue = parameters.listValueKey /> + <#elseif parameters.listValue??> <#assign itemValue = stack.findString(parameters.listValue)/> <#else> diff --git a/core/src/main/resources/template/simple/select.ftl b/core/src/main/resources/template/simple/select.ftl index a0c17b4cd..b0144baf6 100644 --- a/core/src/main/resources/template/simple/select.ftl +++ b/core/src/main/resources/template/simple/select.ftl @@ -70,8 +70,8 @@ <#if parameters.listValueKey??> <#-- checks the valueStack for the 'valueKey.' The valueKey is then looked-up in the locale file for it's localized value. This is then used as a label --> - <#assign valueKey = stack.findString(parameters.listValueKey) /> - <#if valueKey??> + <#assign valueKey = stack.findString(parameters.listValueKey)!'' /> + <#if valueKey?has_content> <#assign itemValue = struts.getText(valueKey) /> <#else> <#assign itemValue = parameters.listValueKey /> diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ui/RadioTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ui/RadioTest.java index 49327406b..1caa5a5bd 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/ui/RadioTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/RadioTest.java @@ -196,6 +196,21 @@ public class RadioTest extends AbstractUITagTest { verify(RadioTag.class.getResource("Radio-7.txt")); } + public void testNotExistingListValueKey() throws Exception { + RadioTag tag = new RadioTag(); + tag.setName("myname"); + tag.setLabel("mylabel"); + tag.setList("#{'a':'aaa', 'b':'bbb', 'c':'ccc'}"); + tag.setListValueKey("notExistingProperty"); + + tag.setPageContext(pageContext); + + tag.doStartTag(); + tag.doEndTag(); + + verify(SelectTag.class.getResource("Radio-8.txt")); + } + private void prepareTagGeneric(RadioTag tag) { TestAction testAction = (TestAction) action; testAction.setFoo("bar"); diff --git a/core/src/test/java/org/apache/struts2/views/jsp/ui/SelectTest.java b/core/src/test/java/org/apache/struts2/views/jsp/ui/SelectTest.java index 01f7300a2..c30b8f5ab 100644 --- a/core/src/test/java/org/apache/struts2/views/jsp/ui/SelectTest.java +++ b/core/src/test/java/org/apache/struts2/views/jsp/ui/SelectTest.java @@ -637,6 +637,21 @@ public class SelectTest extends AbstractUITagTest { verify(SelectTag.class.getResource("Select-13.txt")); } + public void testNotExistingListValueKey() throws Exception { + SelectTag tag = new SelectTag(); + tag.setName("foo"); + tag.setLabel("mylabel"); + tag.setList("#{'a':'aaa', 'b':'bbb', 'c':'ccc'}"); + tag.setListValueKey("notExistingProperty"); + + tag.setPageContext(pageContext); + + tag.doStartTag(); + tag.doEndTag(); + + verify(SelectTag.class.getResource("Select-16.txt")); + } + public class IdName { private String name; private Integer id; diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Radio-8.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Radio-8.txt new file mode 100644 index 000000000..585a0ae00 --- /dev/null +++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Radio-8.txt @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/core/src/test/resources/org/apache/struts2/views/jsp/ui/Select-16.txt b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Select-16.txt new file mode 100644 index 000000000..609e6645e --- /dev/null +++ b/core/src/test/resources/org/apache/struts2/views/jsp/ui/Select-16.txt @@ -0,0 +1,10 @@ + + + + + +