From 6834b78fe9ec33e90530686e9c5101358750a854 Mon Sep 17 00:00:00 2001 From: Przemek Bruski Date: Tue, 9 Dec 2014 17:17:15 +0100 Subject: [PATCH 1/4] WW-4427 - Converters are no longer applied to values coming from the context - fix and UT --- .../com/opensymphony/xwork2/ognl/OgnlValueStack.java | 2 ++ .../opensymphony/xwork2/ognl/OgnlValueStackTest.java | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java index 90b1a543e..ce273b109 100644 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java +++ b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java @@ -351,6 +351,8 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS value = getValue(expr, asType); if (value == null) { value = findInContext(expr); + final XWorkConverter conv = ((Container)getContext().get(ActionContext.CONTAINER)).getInstance(XWorkConverter.class); + return conv.convertValue(getContext(), value, asType); } } finally { context.remove(THROW_EXCEPTION_ON_FAILURE); diff --git a/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java b/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java index e0e949cec..769fcf76c 100644 --- a/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java +++ b/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java @@ -93,6 +93,17 @@ public class OgnlValueStackTest extends XWorkTestCase { assertEquals("1, 2", vs.findValue("childAges", String.class)); } + public void testValuesFromContextAreConverted() { + final OgnlValueStack vs = createValueStack(); + vs.getContext().put(ActionContext.CONTAINER, container); + + final String propertyName = "dogName"; + final String propertyValue = "Rover"; + vs.getContext().put(propertyName, new String[]{propertyValue}); + + assertEquals(propertyValue, vs.findValue(propertyName, String.class)); + } + public void testFailOnException() { OgnlValueStack vs = createValueStack(); From 6a58778399dcdacbe061c55b37a581646871d4ce Mon Sep 17 00:00:00 2001 From: Przemek Bruski Date: Tue, 16 Dec 2014 16:58:38 +0100 Subject: [PATCH 2/4] WW-4427 - inject the converter instead of getting it directly --- .../java/com/opensymphony/xwork2/ognl/OgnlValueStack.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java index ce273b109..48e524163 100644 --- a/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java +++ b/xwork-core/src/main/java/com/opensymphony/xwork2/ognl/OgnlValueStack.java @@ -63,6 +63,7 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS Map overrides; transient OgnlUtil ognlUtil; transient SecurityMemberAccess securityMemberAccess; + private transient XWorkConverter converter; private boolean devMode; private boolean logMissingProperties; @@ -351,8 +352,7 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS value = getValue(expr, asType); if (value == null) { value = findInContext(expr); - final XWorkConverter conv = ((Container)getContext().get(ActionContext.CONTAINER)).getInstance(XWorkConverter.class); - return conv.convertValue(getContext(), value, asType); + return converter.convertValue(getContext(), value, asType); } } finally { context.remove(THROW_EXCEPTION_ON_FAILURE); @@ -475,4 +475,8 @@ public class OgnlValueStack implements Serializable, ValueStack, ClearableValueS securityMemberAccess.setExcludeProperties(excludeProperties); } + @Inject + public void setXWorkConverter(final XWorkConverter converter) { + this.converter = converter; + } } From debaaa2443b854ee0c0cd34ea61ccdc88810e13d Mon Sep 17 00:00:00 2001 From: Przemek Bruski Date: Tue, 16 Dec 2014 17:07:10 +0100 Subject: [PATCH 3/4] WW-4427 - cleaned up UT --- .../java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java b/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java index 769fcf76c..fe045847b 100644 --- a/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java +++ b/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java @@ -95,7 +95,6 @@ public class OgnlValueStackTest extends XWorkTestCase { public void testValuesFromContextAreConverted() { final OgnlValueStack vs = createValueStack(); - vs.getContext().put(ActionContext.CONTAINER, container); final String propertyName = "dogName"; final String propertyValue = "Rover"; From 3a0350f0dc9f27141543bdad62f4881e7eaca6c0 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Tue, 23 Dec 2014 16:07:58 +0100 Subject: [PATCH 4/4] Adds additional use case when value from conext is null --- .../opensymphony/xwork2/ognl/OgnlValueStackTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java b/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java index fe045847b..8c7c3ae44 100644 --- a/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java +++ b/xwork-core/src/test/java/com/opensymphony/xwork2/ognl/OgnlValueStackTest.java @@ -103,6 +103,16 @@ public class OgnlValueStackTest extends XWorkTestCase { 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();