From 1e36c48d5a6cff86ff41dd4334e28191351efff6 Mon Sep 17 00:00:00 2001 From: Keith Donald Date: Tue, 13 May 2008 06:04:34 +0000 Subject: [PATCH] fixed EL-based transition crieria bug --- .../src/defining-flows.xml | 6 ++--- .../booking-faces/.springBeans | 19 +-------------- .../booking-mvc/.springBeans | 19 +-------------- .../booking-portlet-faces/.springBeans | 2 +- .../booking-portlet-mvc/.springBeans | 23 +------------------ .../jsf-booking/.springBeans | 3 +-- .../support/TextToTransitionCriteria.java | 3 +-- .../impl/RequestControlContextImpl.java | 5 ++-- .../WebFlowOgnlExpressionParser.java | 16 ------------- .../el/WebFlowELExpressionParser.java | 1 - .../TextToTransitionCriteriaTests.java | 9 ++++++++ .../WebFlowOgnlExpressionParserTests.java | 11 +++++++++ .../el/WebFlowELExpressionParserTests.java | 2 +- 13 files changed, 33 insertions(+), 86 deletions(-) diff --git a/spring-webflow-reference/src/defining-flows.xml b/spring-webflow-reference/src/defining-flows.xml index 887cbc3e..2dc7701d 100644 --- a/spring-webflow-reference/src/defining-flows.xml +++ b/spring-webflow-reference/src/defining-flows.xml @@ -402,7 +402,7 @@ public interface FlowOutcome { - + ]]> @@ -430,7 +430,7 @@ public interface FlowOutcome { - + ]]> @@ -469,7 +469,7 @@ public interface FlowOutcome { - + diff --git a/spring-webflow-samples/booking-faces/.springBeans b/spring-webflow-samples/booking-faces/.springBeans index 455ff2cf..6fc59d94 100755 --- a/spring-webflow-samples/booking-faces/.springBeans +++ b/spring-webflow-samples/booking-faces/.springBeans @@ -1,30 +1,13 @@ 1 - + - src/main/webapp/WEB-INF/config/web-application-config.xml - src/main/webapp/WEB-INF/config/data-access-config.xml - src/main/webapp/WEB-INF/config/security-config.xml - src/main/webapp/WEB-INF/config/webflow-config.xml - src/main/webapp/WEB-INF/config/webmvc-config.xml - - - true - false - - src/main/webapp/WEB-INF/config/web-application-config.xml - src/main/webapp/WEB-INF/config/data-access-config.xml - src/main/webapp/WEB-INF/config/security-config.xml - src/main/webapp/WEB-INF/config/webflow-config.xml - src/main/webapp/WEB-INF/config/webmvc-config.xml - - diff --git a/spring-webflow-samples/booking-mvc/.springBeans b/spring-webflow-samples/booking-mvc/.springBeans index 92b4d41e..6fc59d94 100755 --- a/spring-webflow-samples/booking-mvc/.springBeans +++ b/spring-webflow-samples/booking-mvc/.springBeans @@ -1,30 +1,13 @@ 1 - + - src/main/webapp/WEB-INF/config/data-access-config.xml - src/main/webapp/WEB-INF/config/security-config.xml - src/main/webapp/WEB-INF/config/web-application-config.xml - src/main/webapp/WEB-INF/config/webflow-config.xml - src/main/webapp/WEB-INF/config/webmvc-config.xml - - - true - false - - src/main/webapp/WEB-INF/config/web-application-config.xml - src/main/webapp/WEB-INF/config/data-access-config.xml - src/main/webapp/WEB-INF/config/security-config.xml - src/main/webapp/WEB-INF/config/webflow-config.xml - src/main/webapp/WEB-INF/config/webmvc-config.xml - - diff --git a/spring-webflow-samples/booking-portlet-faces/.springBeans b/spring-webflow-samples/booking-portlet-faces/.springBeans index ac88622c..6fc59d94 100644 --- a/spring-webflow-samples/booking-portlet-faces/.springBeans +++ b/spring-webflow-samples/booking-portlet-faces/.springBeans @@ -1,7 +1,7 @@ 1 - + diff --git a/spring-webflow-samples/booking-portlet-mvc/.springBeans b/spring-webflow-samples/booking-portlet-mvc/.springBeans index 72dab5ab..6fc59d94 100644 --- a/spring-webflow-samples/booking-portlet-mvc/.springBeans +++ b/spring-webflow-samples/booking-portlet-mvc/.springBeans @@ -1,7 +1,7 @@ 1 - + @@ -9,26 +9,5 @@ - - - true - false - - - - - - true - false - - - - - - true - false - - - diff --git a/spring-webflow-samples/jsf-booking/.springBeans b/spring-webflow-samples/jsf-booking/.springBeans index 5d292705..6fc59d94 100644 --- a/spring-webflow-samples/jsf-booking/.springBeans +++ b/spring-webflow-samples/jsf-booking/.springBeans @@ -1,13 +1,12 @@ 1 - + - src/main/webapp/WEB-INF/web-application-config.xml diff --git a/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/support/TextToTransitionCriteria.java b/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/support/TextToTransitionCriteria.java index 96b1d0f2..19ea034b 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/support/TextToTransitionCriteria.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/engine/builder/support/TextToTransitionCriteria.java @@ -19,7 +19,6 @@ import org.springframework.binding.convert.ConversionExecutionException; import org.springframework.binding.convert.Converter; import org.springframework.binding.expression.Expression; import org.springframework.binding.expression.ExpressionParser; -import org.springframework.binding.expression.ExpressionVariable; import org.springframework.binding.expression.support.FluentParserContext; import org.springframework.util.StringUtils; import org.springframework.webflow.engine.TransitionCriteria; @@ -92,7 +91,7 @@ class TextToTransitionCriteria implements Converter { protected TransitionCriteria createBooleanExpressionTransitionCriteria(String encodedCriteria, ExpressionParser parser) throws ConversionExecutionException { Expression expression = parser.parseExpression(encodedCriteria, new FluentParserContext().template().evaluate( - RequestContext.class).variable(new ExpressionVariable("result", "lastEvent.id"))); + RequestContext.class)); return new DefaultTransitionCriteria(expression); } } \ No newline at end of file diff --git a/spring-webflow/src/main/java/org/springframework/webflow/engine/impl/RequestControlContextImpl.java b/spring-webflow/src/main/java/org/springframework/webflow/engine/impl/RequestControlContextImpl.java index 93882d40..72f4feb4 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/engine/impl/RequestControlContextImpl.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/engine/impl/RequestControlContextImpl.java @@ -228,7 +228,8 @@ class RequestControlContextImpl implements RequestControlContext { public String toString() { return new ToStringCreator(this).append("externalContext", externalContext) - .append("requestScope", requestScope).append("attributes", attributes).append("flowExecution", - flowExecution).toString(); + .append("currentEvent", currentEvent).append("requestScope", requestScope).append("attributes", + attributes).append("messageContext", messageContext).append("flowExecution", flowExecution) + .toString(); } } \ No newline at end of file diff --git a/spring-webflow/src/main/java/org/springframework/webflow/expression/WebFlowOgnlExpressionParser.java b/spring-webflow/src/main/java/org/springframework/webflow/expression/WebFlowOgnlExpressionParser.java index 21abb321..08139c2d 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/expression/WebFlowOgnlExpressionParser.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/expression/WebFlowOgnlExpressionParser.java @@ -34,7 +34,6 @@ import org.springframework.webflow.context.ExternalContextHolder; import org.springframework.webflow.core.collection.MutableAttributeMap; import org.springframework.webflow.engine.AnnotatedAction; import org.springframework.webflow.execution.Action; -import org.springframework.webflow.execution.Event; import org.springframework.webflow.execution.RequestContext; /** @@ -55,7 +54,6 @@ public class WebFlowOgnlExpressionParser extends OgnlExpressionParser { addPropertyAccessor(MessageSource.class, new MessageSourcePropertyAccessor()); addPropertyAccessor(RequestContext.class, new RequestContextPropertyAccessor(new ObjectPropertyAccessor())); addPropertyAccessor(Action.class, new ActionPropertyAccessor()); - addPropertyAccessor(Event.class, new EventPropertyAccessor()); } /** @@ -215,20 +213,6 @@ public class WebFlowOgnlExpressionParser extends OgnlExpressionParser { } } - /** - * Resolves event attributes. - */ - private static class EventPropertyAccessor implements PropertyAccessor { - public Object getProperty(Map context, Object target, Object name) throws OgnlException { - Event event = (Event) target; - return event.getAttributes().get(name.toString()); - } - - public void setProperty(Map context, Object target, Object name, Object value) throws OgnlException { - throw new OgnlException("Cannot set attributes on an Event instance - operation not allowed"); - } - } - /** * Resolves messages. */ diff --git a/spring-webflow/src/main/java/org/springframework/webflow/expression/el/WebFlowELExpressionParser.java b/spring-webflow/src/main/java/org/springframework/webflow/expression/el/WebFlowELExpressionParser.java index f8f2c856..21ed0f61 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/expression/el/WebFlowELExpressionParser.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/expression/el/WebFlowELExpressionParser.java @@ -58,7 +58,6 @@ public class WebFlowELExpressionParser extends ELExpressionParser { customResolvers.add(new ImplicitFlowVariableELResolver(context)); customResolvers.add(new ScopeSearchingELResolver(context)); customResolvers.add(new SpringBeanWebFlowELResolver(context)); - customResolvers.add(new EventAttributesElResolver()); customResolvers.add(new ActionMethodELResolver()); ELResolver resolver = new DefaultELResolver(customResolvers); return new WebFlowELContext(resolver); diff --git a/spring-webflow/src/test/java/org/springframework/webflow/engine/builder/support/TextToTransitionCriteriaTests.java b/spring-webflow/src/test/java/org/springframework/webflow/engine/builder/support/TextToTransitionCriteriaTests.java index 1e31029b..97d158e1 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/engine/builder/support/TextToTransitionCriteriaTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/engine/builder/support/TextToTransitionCriteriaTests.java @@ -83,6 +83,15 @@ public class TextToTransitionCriteriaTests extends TestCase { assertTrue("Criterion should evaluate to true", criterion.test(ctx)); } + public void testCurrenEventEval() throws Exception { + String expression = "${currentEvent == 'submit'}"; + TransitionCriteria criterion = (TransitionCriteria) converter.convert(expression, TransitionCriteria.class, + null); + MockRequestContext ctx = getRequestContext(); + ctx.setCurrentEvent(new Event(this, "submit")); + assertTrue("Criterion should evaluate to true", criterion.test(ctx)); + } + public void testNullExpressionEvaluation() throws Exception { serviceLocator.getFlowBuilderServices().setExpressionParser(new ExpressionParser() { public Expression parseExpression(String expressionString, ParserContext context) throws ParserException { diff --git a/spring-webflow/src/test/java/org/springframework/webflow/expression/WebFlowOgnlExpressionParserTests.java b/spring-webflow/src/test/java/org/springframework/webflow/expression/WebFlowOgnlExpressionParserTests.java index ba65e356..d22b0d28 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/expression/WebFlowOgnlExpressionParserTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/expression/WebFlowOgnlExpressionParserTests.java @@ -16,6 +16,7 @@ import org.springframework.webflow.core.collection.MutableAttributeMap; import org.springframework.webflow.engine.AnnotatedAction; import org.springframework.webflow.engine.StubViewFactory; import org.springframework.webflow.engine.ViewState; +import org.springframework.webflow.execution.Event; import org.springframework.webflow.execution.RequestContext; import org.springframework.webflow.execution.TestAction; import org.springframework.webflow.test.MockRequestContext; @@ -173,6 +174,16 @@ public class WebFlowOgnlExpressionParserTests extends TestCase { assertEquals("setupForm", action.getMethod()); } + public void testResolveEventAttributes() { + MockRequestContext context = new MockRequestContext(); + LocalAttributeMap attributes = new LocalAttributeMap(); + attributes.put("foo", "bar"); + context.setCurrentEvent(new Event(this, "event", attributes)); + Expression exp = parser.parseExpression("currentEvent.attributes.foo", new FluentParserContext() + .evaluate(RequestContext.class)); + assertEquals("bar", exp.getValue(context)); + } + public void testResolveMessage() { MockRequestContext context = new MockRequestContext(); StaticApplicationContext ac = new StaticApplicationContext(); diff --git a/spring-webflow/src/test/java/org/springframework/webflow/expression/el/WebFlowELExpressionParserTests.java b/spring-webflow/src/test/java/org/springframework/webflow/expression/el/WebFlowELExpressionParserTests.java index 16c708ae..07a1e54e 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/expression/el/WebFlowELExpressionParserTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/expression/el/WebFlowELExpressionParserTests.java @@ -177,7 +177,7 @@ public class WebFlowELExpressionParserTests extends TestCase { LocalAttributeMap attributes = new LocalAttributeMap(); attributes.put("foo", "bar"); context.setCurrentEvent(new Event(this, "event", attributes)); - Expression exp = parser.parseExpression("currentEvent.foo", new FluentParserContext() + Expression exp = parser.parseExpression("currentEvent.attributes.foo", new FluentParserContext() .evaluate(RequestContext.class)); assertEquals("bar", exp.getValue(context)); }