在其他 bean 未完成时创建一个新的 FlowScoped bean

问题描述 投票:0回答:1

我在 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的流bean:

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

第二种配置:

public class OrderFlow implements 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的流bean:

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

我的案例:

  1. 用户打开页面,点击 h: 按钮启动“requestFlow”(没有完成!)

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

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

第一个未完成时如何创建新的 FlowScoped bean?

jsf jakarta-ee cdi flow-scope
1个回答
1
投票

所以,正好在 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>
© www.soinside.com 2019 - 2024. All rights reserved.