From 2825fdb41ad765e1820812b7fe5be7c76d913f7f Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Tue, 4 Jan 2022 20:21:28 +0100 Subject: [PATCH] WW-5117 Evaluates dynamic attributes when assigning them to tag Reverts https://github.com/apache/struts/pull/447/commits/8bbe1949e17d58e1b5aef9c71e1279ad12ad7ba7#diff-0a39f082871f48bd14037ab2e3a3911b0b1046506c1d93338024d77d412a7075L305-L309 --- .../org/apache/struts2/components/UIBean.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/apache/struts2/components/UIBean.java b/core/src/main/java/org/apache/struts2/components/UIBean.java index 2dc82f630..fdf288fca 100644 --- a/core/src/main/java/org/apache/struts2/components/UIBean.java +++ b/core/src/main/java/org/apache/struts2/components/UIBean.java @@ -21,6 +21,7 @@ package org.apache.struts2.components; import com.opensymphony.xwork2.config.ConfigurationException; import com.opensymphony.xwork2.inject.Inject; import com.opensymphony.xwork2.util.ValueStack; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -30,6 +31,7 @@ import org.apache.struts2.components.template.Template; import org.apache.struts2.components.template.TemplateEngine; import org.apache.struts2.components.template.TemplateEngineManager; import org.apache.struts2.components.template.TemplateRenderingContext; +import org.apache.struts2.util.ComponentUtils; import org.apache.struts2.util.TextProviderHelper; import org.apache.struts2.views.annotations.StrutsTagAttribute; import org.apache.struts2.views.util.ContextUtil; @@ -1258,20 +1260,25 @@ public abstract class UIBean extends Component { public void setDynamicAttributes(Map tagDynamicAttributes) { for (Map.Entry entry : tagDynamicAttributes.entrySet()) { - String key = entry.getKey(); + String attrName = entry.getKey(); + String attrValue = entry.getValue(); - if (!isValidTagAttribute(key)) { - dynamicAttributes.put(key, entry.getValue()); + if (!isValidTagAttribute(attrName)) { + if (ComponentUtils.altSyntax(getStack()) && ComponentUtils.isExpression(attrValue)) { + dynamicAttributes.put(attrName, String.valueOf(ObjectUtils.defaultIfNull(findString(attrValue), attrValue))); + } else { + dynamicAttributes.put(attrName, attrValue); + } } } } - @Override /** * supports dynamic attributes for freemarker ui tags - * @see https://issues.apache.org/jira/browse/WW-3174 - * @see https://issues.apache.org/jira/browse/WW-4166 + * @see "https://issues.apache.org/jira/browse/WW-3174" + * @see "https://issues.apache.org/jira/browse/WW-4166" */ + @Override public void copyParams(Map params) { super.copyParams(params); for (Object o : params.entrySet()) {