在另一个未完成时创建一个新的 FlowScoped bean
Create a new FlowScoped bean when other one was not finished
我正在 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 实现 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:button 启动 "requestFlow"(未完成!)
使用菜单导航到另一个页面,通过单击 h:button 尝试启动 "orderFlow"。
问题:
"OrderFlow" 没有在控制台中没有任何错误的情况下启动!第一个流还在内存中,但根据文档,它必须被销毁。
所以,我希望能够在其他 bean 未完成时创建一个新的 FlowScoped bean。
有什么建议吗?
所以,正好在 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>
我正在 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 实现 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:button 启动 "requestFlow"(未完成!)
使用菜单导航到另一个页面,通过单击 h:button 尝试启动 "orderFlow"。
问题: "OrderFlow" 没有在控制台中没有任何错误的情况下启动!第一个流还在内存中,但根据文档,它必须被销毁。
所以,我希望能够在其他 bean 未完成时创建一个新的 FlowScoped bean。
有什么建议吗?
所以,正好在 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>