1

I am working whith JSF (Primeface) and j2ee on weblogic.

I have two different flows in my application:

Flow configuration:

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's flow bean:

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

Second configuration:

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's flow bean:

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

My Case:

  1. User opens page where by clicking h:button starts the "requestFlow" (doesn't finish it!)

  2. They use the menu to navigate to another page and try to start the "orderFlow" by clicking h:button.

Problem: "OrderFlow" didn't start and there is no error in the console. Also, the first flow still in memory, but according to documentation it has to be destroyed.

How can I create a new FlowScoped bean when the first one was not finished?

TarHalda
  • 1,050
  • 1
  • 9
  • 27
Aleksei
  • 104
  • 8

1 Answers1

1

So, exactly in 2 month i found the answer. The trick is how you start your flow. If you want to run new JSF flow, while didn't finish other one, you have to remove from JSF context previous instances of any flow. In order to do it, you have add method in controller:

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();
}

And start flow page in the next way:

<p:commandButton value="Start Flow"
    action="#{controller.initFlow}"/>
</p:panelGrid>
Aleksei
  • 104
  • 8