fixed EL-based transition crieria bug
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user