From 0d8f4d43bd2453abcd302cdf44b045c573d5c554 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Fri, 20 Apr 2012 22:19:41 +0000 Subject: [PATCH] WW-3804 adds support of dynamic attributes to tag and extends support for dynamic attributes with expression evaluation git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1328526 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/struts2/util/StrutsUtil.java | 5 +++ .../template/simple/dynamic-attributes.ftl | 4 ++- .../resources/template/simple/radiomap.ftl | 1 + .../apache/struts2/util/StrutsUtilTest.java | 31 ++++++++++++------- .../struts2/views/jsp/ui/RadioTest.java | 30 ++++++++++++++++-- .../apache/struts2/views/jsp/ui/Radio-7.txt | 7 +++++ 6 files changed, 62 insertions(+), 16 deletions(-) create mode 100644 core/src/test/resources/org/apache/struts2/views/jsp/ui/Radio-7.txt diff --git a/core/src/main/java/org/apache/struts2/util/StrutsUtil.java b/core/src/main/java/org/apache/struts2/util/StrutsUtil.java index f55e6f0c6..d64a58fee 100644 --- a/core/src/main/java/org/apache/struts2/util/StrutsUtil.java +++ b/core/src/main/java/org/apache/struts2/util/StrutsUtil.java @@ -25,6 +25,7 @@ import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ObjectFactory; import com.opensymphony.xwork2.inject.Container; import com.opensymphony.xwork2.util.ClassLoaderUtil; +import com.opensymphony.xwork2.util.TextParseUtil; import com.opensymphony.xwork2.util.ValueStack; import com.opensymphony.xwork2.util.logging.Logger; import com.opensymphony.xwork2.util.logging.LoggerFactory; @@ -148,6 +149,10 @@ public class StrutsUtil { return (request == null)? "" : request.getContextPath(); } + public String translateVariables(String expression) { + return TextParseUtil.translateVariables(expression, stack); + } + /** * the selectedList objects are matched to the list.listValue *

diff --git a/core/src/main/resources/template/simple/dynamic-attributes.ftl b/core/src/main/resources/template/simple/dynamic-attributes.ftl index 1edf7bc8f..dc5c3be85 100644 --- a/core/src/main/resources/template/simple/dynamic-attributes.ftl +++ b/core/src/main/resources/template/simple/dynamic-attributes.ftl @@ -23,6 +23,8 @@ <#if (parameters.dynamicAttributes?? && parameters.dynamicAttributes?size > 0)><#rt/> <#assign aKeys = parameters.dynamicAttributes.keySet()><#rt/> <#list aKeys as aKey><#rt/> - ${aKey}="${parameters.dynamicAttributes[aKey]?html}"<#rt/> + <#assign keyValue = parameters.dynamicAttributes[aKey]/> + <#assign value = struts.translateVariables(keyValue)!keyValue/> + ${aKey}="${value?html}"<#rt/> <#rt/> <#rt/> \ No newline at end of file diff --git a/core/src/main/resources/template/simple/radiomap.ftl b/core/src/main/resources/template/simple/radiomap.ftl index 4b07f6895..fa5f9ac3b 100644 --- a/core/src/main/resources/template/simple/radiomap.ftl +++ b/core/src/main/resources/template/simple/radiomap.ftl @@ -61,6 +61,7 @@ <#include "/${parameters.templateDir}/simple/scripting-events.ftl" /> <#include "/${parameters.templateDir}/simple/common-attributes.ftl" /> +<#include "/${parameters.templateDir}/simple/dynamic-attributes.ftl" /> /><#rt/>