0

我在 weblogic 上使用 JSF (Primeface) 和 j2ee。

所以,我的应用程序中有两个不同的流程:

流量配置:

public class RequestFlow implements Serializable {
@Produces
@FlowDefinition
public Flow defineFlow(@FlowBuilderParameter FlowBuilder flowBuilder) {
    String flowId = "requestFlow";
    flowBuilder.id("", flowId);
    flowBuilder.viewNode(flowId, "/inside/customer/request/flow/requestFlow.xhtml").markAsStartNode();
    flowBuilder.viewNode("requestFlowCart", "/inside/customer/request/flow/requestFlowCart.xhtml");
    flowBuilder.viewNode("requestFlowCheckout", "/inside/customer/request/flow/requestFlowCheckout.xhtml");
    flowBuilder.returnNode("finishRequest").fromOutcome("/inside/customer/request/requests.xhtml");

    return flowBuilder.getFlow();
}
}

CDI的流豆:

@Named
@FlowScoped("requestFlow")
public class RequestFlowBean implements Serializable {
   //some logic
}

第二种配置:

公共类 OrderFlow 实现 Serializable {

@Produces
@FlowDefinition
public Flow defineFlow(@FlowBuilderParameter FlowBuilder flowBuilder) {
    String flowId = "orderFlow";
    flowBuilder.id("", flowId);
    flowBuilder.viewNode(flowId, "/inside/customer/order/flow/orderFlow.xhtml").markAsStartNode();
    flowBuilder.viewNode("orderFlowSelectRequests", "/inside/customer/order/flow/orderFlowSelectRequests.xhtml");
    flowBuilder.viewNode("orderFlowReviewRequests", "/inside/customer/order/flow/orderFlowReviewRequests.xhtml");
    flowBuilder.viewNode("orderFlowCheckoutOrder", "/inside/customer/order/flow/orderFlowCheckoutOrder.xhtml");
    flowBuilder.returnNode("finishOrder").fromOutcome("/inside/customer/order/orders.xhtml");

    return flowBuilder.getFlow();
}
}

CDI的流豆:

@Named
@FlowScoped("orderFlow")
public class OrderFlowBean implements Serializable {
    //some logic
}

我的情况:

  1. 用户打开页面,通过单击 h:button 启动“requestFlow”(没有完成它!)

  2. 使用菜单导航到另一个页面,通过单击 h:button 尝试启动“orderFlow”。

问题:“OrderFlow”在控制台中没有任何错误启动!第一个流程仍在内存中,但根据文档,它必须被销毁。

所以,我希望能够在另一个没有完成时创建一个新的 FlowScoped bean。

有什么建议么?

4

1 回答 1

0

所以,正好在 2 个月内,我找到了答案。诀窍是你如何开始你的流程。如果您想运行新的 JSF 流,而没有完成其他流,则必须从 JSF 上下文中删除任何流的先前实例。为了做到这一点,您在控制器中添加了方法:

public String initFlow() {
    FacesContext context = FacesContext.getCurrentInstance();
    FlowHandler handler = context.getApplication().getFlowHandler();

    ExternalContext extContext = context.getExternalContext();
    String sessionKey = extContext.getClientWindow().getId() + "_flowStack";
    Map<String, Object> sessionMap = extContext.getSessionMap();
    if (sessionMap.containsKey(sessionKey)) {
        sessionMap.remove(sessionKey);
    }
    handler.transition(context, null, handler.getFlow(context, "", getFlowName()), null, "");
    return getFlowName();
}

并以以下方式启动流页面:

<p:commandButton value="Start Flow"
    action="#{controller.initFlow}"/>
</p:panelGrid>
于 2017-05-22T09:51:01.590 回答