mirror of
https://github.com/apache/struts.git
synced 2026-08-11 01:27:14 +00:00
WW-4427 Converts value retrieved from context
This commit is contained in:
@@ -63,6 +63,7 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS
|
||||
Map<Object, Object> overrides;
|
||||
transient OgnlUtil ognlUtil;
|
||||
transient SecurityMemberAccess securityMemberAccess;
|
||||
private transient XWorkConverter converter;
|
||||
|
||||
private boolean devMode;
|
||||
private boolean logMissingProperties;
|
||||
@@ -351,6 +352,7 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS
|
||||
value = getValue(expr, asType);
|
||||
if (value == null) {
|
||||
value = findInContext(expr);
|
||||
return converter.convertValue(getContext(), value, asType);
|
||||
}
|
||||
} finally {
|
||||
context.remove(THROW_EXCEPTION_ON_FAILURE);
|
||||
@@ -473,4 +475,8 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS
|
||||
securityMemberAccess.setExcludeProperties(excludeProperties);
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setXWorkConverter(final XWorkConverter converter) {
|
||||
this.converter = converter;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +93,26 @@ public class OgnlValueStackTest extends XWorkTestCase {
|
||||
assertEquals("1, 2", vs.findValue("childAges", String.class));
|
||||
}
|
||||
|
||||
public void testValuesFromContextAreConverted() {
|
||||
final OgnlValueStack vs = createValueStack();
|
||||
|
||||
final String propertyName = "dogName";
|
||||
final String propertyValue = "Rover";
|
||||
vs.getContext().put(propertyName, new String[]{propertyValue});
|
||||
|
||||
assertEquals(propertyValue, vs.findValue(propertyName, String.class));
|
||||
}
|
||||
|
||||
public void testNullValueFromContextGetsConverted() {
|
||||
final OgnlValueStack vs = createValueStack();
|
||||
|
||||
final String propertyName = "dogName";
|
||||
final String propertyValue = null;
|
||||
vs.getContext().put(propertyName, propertyValue);
|
||||
|
||||
assertEquals(propertyValue, vs.findValue(propertyName, String.class));
|
||||
}
|
||||
|
||||
public void testFailOnException() {
|
||||
OgnlValueStack vs = createValueStack();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user