我正在使用JSF(Primeface)和j2ee在weblogic上工作。
所以,我的应用程序中有两个不同的流程:
流程配置:
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
}
第二种配置:
公共类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的流程bean:
@Named
@FlowScoped("orderFlow")
public class OrderFlowBean implements Serializable {
//some logic
}
我的案例:
用户打开页面,点击h:按钮启动“requestFlow”(未完成!)
使用菜单导航到另一个页面,点击h:按钮尝试启动“orderFlow”。
问题: “OrderFlow”在控制台没有任何错误的情况下无法启动!并且第一个流程仍在记忆中,但根据文档,它必须被销毁。
所以,我希望能够在其他的bean未完成时创建一个新的FlowScoped bean。
有什么建议吗?
答案 0 :(得分: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>