在“ org.springframework.webflow.engine.impl.RequestControlContextImpl”类型的对象上找不到属性或字段“ httpServletRequest”

时间:2019-03-09 19:57:01

标签: java spring spring-webflow

我有一个注册流程,该流程检查用户的cookie,为此,我需要处理HttpServletRequest。我创建了一个方法,该方法将HttpServletRequest用作参数,并且还有一个决策状态,该请求将请求发送到我的方法。

我的方法:

public Boolean checkCartOnExisting(HttpServletRequest request) {
    currentCookie =  Arrays.stream(request.getCookies()).filter(cok -> cok.getName().equals("book_cart")).findFirst().get();
    return Arrays.stream(request.getCookies()).anyMatch((cookie) -> cookie.getName() == "book_cart");
}

我的决定状态:

<decision-state id="checkCart">
    <if test="orderFlowService.checkCartOnExisting(httpServletRequest)" then="addUserWithCart" else="saveUser" />
</decision-state>

运行程序时出现此错误:

   org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'httpServletRequest' cannot be found on object of type 'org.springframework.webflow.engine.impl.RequestControlContextImpl' - maybe not public or not valid?
org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:217)
org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:104)
org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:91)
org.springframework.expression.spel.ast.MethodReference.getArguments(MethodReference.java:163)
org.springframework.expression.spel.ast.MethodReference.getValueRef(MethodReference.java:80)
org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:68)
org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:89)
org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:114)
org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:300)
org.springframework.binding.expression.spel.SpringELExpression.getValue(SpringELExpression.java:94)
org.springframework.webflow.engine.support.DefaultTransitionCriteria.test(DefaultTransitionCriteria.java:48)
org.springframework.webflow.engine.Transition.matches(Transition.java:185)
org.springframework.webflow.engine.TransitionSet.getTransition(TransitionSet.java:124)
org.springframework.webflow.engine.TransitionableState.getRequiredTransition(TransitionableState.java:88)
org.springframework.webflow.engine.DecisionState.doEnter(DecisionState.java:51)
org.springframework.webflow.engine.State.enter(State.java:194)

1 个答案:

答案 0 :(得分:2)

在您的决定状态下,您可以使用externalContext.nativeRequest

<decision-state id="checkCart">
    <if test="orderFlowService.checkCartOnExisting(externalContext.nativeRequest)" then="addUserWithCart" else="saveUser"/>
</decision-state>