mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
WW-3644 changes support for expression as a dynamic attribute to parse only values enclosed in %{ and }
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1381585 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -278,7 +278,7 @@ public class Component {
|
||||
public static String stripExpressionIfAltSyntax(ValueStack stack, String expr) {
|
||||
if (altSyntax(stack)) {
|
||||
// does the expression start with %{ and end with }? if so, just cut it off!
|
||||
if (expr.startsWith("%{") && expr.endsWith("}")) {
|
||||
if (isExpression(expr)) {
|
||||
return expr.substring(2, expr.length() - 1);
|
||||
}
|
||||
}
|
||||
@@ -511,10 +511,16 @@ public class Component {
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrite to set if body shold be used.
|
||||
* Overwrite to set if body should be used.
|
||||
* @return always false for this component.
|
||||
*/
|
||||
public boolean usesBody() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isExpression(Object value) {
|
||||
String expr = value.toString();
|
||||
return expr.startsWith("%{") && expr.endsWith("}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
package org.apache.struts2.views.jsp.ui;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.struts2.components.Component;
|
||||
import org.apache.struts2.components.UIBean;
|
||||
import org.apache.struts2.views.jsp.ComponentTagSupport;
|
||||
|
||||
@@ -291,10 +292,11 @@ public abstract class AbstractUITag extends ComponentTagSupport implements Dynam
|
||||
}
|
||||
|
||||
public void setDynamicAttribute(String uri, String localName, Object value) throws JspException {
|
||||
if (value != null && value instanceof String) {
|
||||
if (Component.altSyntax(getStack()) && Component.isExpression(value)) {
|
||||
dynamicAttributes.put(localName, String.valueOf(ObjectUtils.defaultIfNull(findValue(value.toString()), value)));
|
||||
} else {
|
||||
dynamicAttributes.put(localName, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@ import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import static org.apache.struts2.views.jsp.AbstractUITagTest.normalize;
|
||||
|
||||
/**
|
||||
* Test case for FreeMarkerResult.
|
||||
*
|
||||
@@ -262,7 +264,7 @@ public class FreeMarkerResultTest extends StrutsTestCase {
|
||||
+ "\n"
|
||||
+ "<input type=\"radio\" name=\"car\" id=\"carford\" value=\"ford\"/><label for=\"carford\">Ford Motor Co</label>\n"
|
||||
+ "<input type=\"radio\" name=\"car\" id=\"cartoyota\" value=\"toyota\"/><label for=\"cartoyota\">Toyota</label>\n";
|
||||
assertEquals(expected, stringWriter.toString());
|
||||
assertEquals(normalize(expected), normalize(stringWriter.toString()));
|
||||
}
|
||||
|
||||
public void testDynamicAttributesInTheme() throws Exception {
|
||||
|
||||
@@ -71,7 +71,7 @@ public class AnchorTest extends AbstractUITagTest {
|
||||
AnchorTag tag = createTag();
|
||||
tag.setHref("a");
|
||||
|
||||
tag.setDynamicAttribute("uri", "placeholder", "foo");
|
||||
tag.setDynamicAttribute("uri", "placeholder", "%{foo}");
|
||||
|
||||
tag.doStartTag();
|
||||
tag.doEndTag();
|
||||
|
||||
Reference in New Issue
Block a user