【问题标题】:Anyone succesfully integrated JSF 2 ViewScoped beans with Spring WebFlow 2?任何人成功地将 JSF 2 ViewScoped bean 与 Spring WebFlow 2 集成?
【发布时间】:2014-09-13 19:10:15
【问题描述】:

我们使用@ManagedBean 和@ViewScoped 注释了JSF 2 托管bean。然后在我们的 Spring WebFlow flow.xml 文件中;像 on-start 和 on-entry 这样的状态更改定义开始抱怨它无法在任何范围内找到托管 bean。

Jul 22, 2014 11:04:43 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jul 22, 2014 11:04:43 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jul 22, 2014 11:04:43 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 32586 ms
Jul 22, 2014 11:05:01 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [springMVCServlet] in context with path [/opp] threw exception [Request processing failed; nested exception is org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing [AnnotatedAction@1e4c320 targetAction = [EvaluateAction@1c6a657 expression = serviceProviderSubscriptionBB.loadServiceProviderSubscription(subscriptionHeaderId), resultExpression = [null]], attributes = map[[empty]]] in state 'null' of flow 'service-provider-subscription' -- action execution attributes were 'map[[empty]]'] with root cause
org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Property or field 'serviceProviderSubscriptionBB' cannot be found on object of type 'org.springframework.webflow.engine.impl.RequestControlContextImpl' - maybe not public?
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:215)
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:85)
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:78)
    at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:48)
    at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:84)
    at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:114)
    at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:105)
    at org.springframework.binding.expression.spel.SpringELExpression.getValue(SpringELExpression.java:84)
    at org.springframework.webflow.action.EvaluateAction.doExecute(EvaluateAction.java:75)
    at org.springframework.webflow.action.AbstractAction.execute(AbstractAction.java:188)
    at org.springframework.webflow.execution.AnnotatedAction.execute(AnnotatedAction.java:145)
    at org.springframework.webflow.execution.ActionExecutor.execute(ActionExecutor.java:51)
    at org.springframework.webflow.engine.ActionList.execute(ActionList.java:154)
    at org.springframework.webflow.engine.Flow.start(Flow.java:526)
    at org.springframework.webflow.engine.impl.FlowExecutionImpl.start(FlowExecutionImpl.java:368)
    at org.springframework.webflow.engine.impl.FlowExecutionImpl.start(FlowExecutionImpl.java:223)



<on-start>

    <evaluate
        expression="serviceProviderSubscriptionBB.loadServiceProviderSubscription(subscriptionHeaderId)" />

</on-start>

我们面临的另一个问题是; @ViewScoped bean 上的销毁回调永远不会被调用。我们在每个不同的 JSF 视图中都获得了新的 bean 实例,但我们不知道旧的和注入其中的依赖 bean。

谁能帮忙?

谢谢。

【问题讨论】:

  • 您使用的是哪个@ViewScoped?您不能将 CDI 视图范围与 JSF bean 一起使用。另外,您需要命名托管 bean 或在 bean.xml 文件中声明和命名它。代替 JSF 的 @ManagedBean 使用 CDI 的 @Named,因为前者注定要被弃用。
  • 显示代码失败的地方。
  • javax.faces.bean.ViewScoped。如果我们使用@Named,我们可以让它只在 JSF 视图中可用吗?我们能否在 WebFlow 流 xml 文件的状态更改定义(启动、进入、渲染、退出等)中访问这些 bean?
  • @mrtbykkl 我从来没有使用过spring,所以不能给你太多建议,但可以确定CDI 的bean 比JSF 的托管bean 更容易访问/公开。您应该将 CDI 用于任何类型的框架集成工作。回答您的第一个问题:是的,但使用javax.faces.view.ViewScoped 而不是javax.faces.bean.ViewScoped

标签: jsf jsf-2 spring-webflow spring-webflow-2


【解决方案1】:

流文件只知道如何使用 Spring Beans。

您可以使用 @Component('serviceProviderSubscriptionBB') 注释您的 ManagedBean 并让 spring 处理它,或者您可以直接在流 &lt;var name="serviceProviderSubscriptionBB" class="the full name of your class"/&gt; 上声明托管 bean,这样您的类将在整个流中可用。

希望对你有帮助!

【讨论】:

    猜你喜欢
    • 2013-09-02
    • 1970-01-01
    • 2015-11-08
    • 2010-09-24
    • 2015-06-29
    • 2014-07-01
    • 2016-11-12
    • 2011-02-18
    • 2020-01-21
    相关资源
    最近更新 更多