0
votes

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

So, 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. Using menu navigates to another page, by clicking h:button tries to start the "orderFlow".

Problem: "OrderFlow" wasn't start without any error in console! And the first flow still in memory, but according documentation it have to be destroyed.

So, I want to be able create a new FlowScoped bean when other one was not finished.

Any suggestions?

1

1 Answers

0
votes

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>