From 7f586d39b7f8411e22fd13de8025f1866477fc3c Mon Sep 17 00:00:00 2001 From: adam brin Date: Tue, 18 Mar 2014 07:36:28 -0700 Subject: [PATCH 1/2] [PATCH] First attempt at enabling value-labels to be pulled from Locale Files. Adding listValueKey attribute to checkboxList, radioMap, and select tags. Issues: This implementation uses the <@s.text> tag to handle the localization with an assignment. I presume this is less than idea, but I lack the knowledge of the Struts2 tag model that would suggest where to check for this on the valueStack or elsewhere. Example: public enum yesno { YES, NO; } <@s.radio name="yes no" list="#{yesno.values()}" valueKey="name()" /> + <#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}"/> + <#elseif parameters.listValue??> <#assign itemValue = stack.findString(parameters.listValue)?default("")/> <#else> <#assign itemValue = stack.findString('top')/> diff --git a/core/src/main/resources/template/simple/radiomap.ftl b/core/src/main/resources/template/simple/radiomap.ftl index ab6d42cffd..183fd57618 100644 --- a/core/src/main/resources/template/simple/radiomap.ftl +++ b/core/src/main/resources/template/simple/radiomap.ftl @@ -27,7 +27,13 @@ <#assign itemKey = stack.findValue('top')/> <#assign itemKeyStr = itemKey.toString() /> - <#if parameters.listValue??> + <#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}"/> + <#elseif parameters.listValue??> <#assign itemValue = stack.findString(parameters.listValue)/> <#else> <#assign itemValue = stack.findString('top')/> diff --git a/core/src/main/resources/template/simple/select.ftl b/core/src/main/resources/template/simple/select.ftl index 74277e6ae3..f4f27bfc24 100644 --- a/core/src/main/resources/template/simple/select.ftl +++ b/core/src/main/resources/template/simple/select.ftl @@ -69,7 +69,13 @@ <#assign itemKey = stack.findValue('top')/> <#assign itemKeyStr = stack.findString('top')> - <#if parameters.listValue??> + <#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}"/> + <#elseif parameters.listValue??> <#if stack.findString(parameters.listValue)??> <#assign itemValue = stack.findString(parameters.listValue)/> <#else> From 6def514524e81c4af188b47b6694384eea3a46c6 Mon Sep 17 00:00:00 2001 From: adam brin Date: Mon, 24 Mar 2014 07:31:54 -0700 Subject: [PATCH 2/2] updating ListUIBean updating java-backed bean --- .../org/apache/struts2/components/ListUIBean.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/src/main/java/org/apache/struts2/components/ListUIBean.java b/core/src/main/java/org/apache/struts2/components/ListUIBean.java index b1a4493b6f..69deae4c1a 100644 --- a/core/src/main/java/org/apache/struts2/components/ListUIBean.java +++ b/core/src/main/java/org/apache/struts2/components/ListUIBean.java @@ -48,6 +48,7 @@ public abstract class ListUIBean extends UIBean { protected Object list; protected String listKey; + protected String listValueKey; protected String listValue; protected String listCssClass; protected String listCssStyle; @@ -108,6 +109,13 @@ public void evaluateExtraParams() { addParameter("listKey", "key"); } + if (listValueKey != null) { + listValueKey = stripExpressionIfAltSyntax(listValueKey); + addParameter("listValueKey", listValueKey); + } else if (value instanceof Map) { + addParameter("listValueKey", "valueKey"); + } + if (listValue != null) { listValue = stripExpressionIfAltSyntax(listValue); addParameter("listValue", listValue); @@ -147,6 +155,11 @@ public void setListKey(String listKey) { this.listKey = listKey; } + @StrutsTagAttribute(description = " Property of list objects to get field value label from") + public void setListValueKey(String listValueKey) { + this.listValueKey = listValueKey; + } + @StrutsTagAttribute(description = "Property of list objects to get field content from") public void setListValue(String listValue) { this.listValue = listValue;