我有一个基本的工作流程示例:
src/main/webapp
|
|- index.xhtml
|- flow1
|- flow1-flow.xml
|- flow1.xhtml
index.xhtml有一个简单的表单,它使用一个参数进入流:
<h:form>
Click to enter flow1
<h:commandButton action="flow1" value="Flow 1">
<f:param name="testInput" value="hi there"/>
</h:commandButton>
</h:form>
flow1.xhtml显示参数并允许您在flow作用域中输入值:
<h:form>
Hi this is page 1.
<h:inputText label="Enter something:" value="#{flowScope.testOutput}"/><br/>
Request parameter: #{param['testInput']}<br/>
<h:commandButton action="returnFromFlow1"/>
</h:form>
the只是将返回节点定义为"returnFromFlow1“并将其设置为/index.xhtml。
这似乎起作用了。我想在进入流时实现post-redirect-get,以便浏览器地址栏与视图保持同步。所以我很自然地尝试了action="flow1?faces-redirect=true“。此更改会阻止流执行..它只是在单击按钮时重新加载index.xhtml。
然后我尝试了action="flow1/flow1.xhtml?faces-redirect=true".这会加载页面并按预期进行重定向,但流并未初始化。当我在流程中提交表单时,我得到一个关于flowScope解析为空的错误。
在做了一些研究后,我发现了一个设置" to - flow -document-id“以强制其初始化流的提示。所以我添加了我的命令按钮。没有变化。
有没有关于如何做到这一点的想法?
发布于 2017-07-22 08:36:14
如果唯一的要求是浏览器地址栏与视图保持同步,那么您可以简单地使用<h:button
而不是<h:commandButton
。这之所以有效,是因为<h:button
使用Javascript生成HTTP GET请求来启动和导航到流。流的ID必须指定为outcome
属性的值:
index.xhtml:
<h:form>
Click to enter flow1
<h:button outcome="flow1" value="Flow 1">
<f:param name="testInput" value="hi there" />
</h:button>
</h:form>
另请参阅:
如果要求在授予启动流程的权限之前必须执行一些检查,则必须手动初始化并导航到流程,如下所示:
index.xhtml:
<h:form>
Click to enter flow1
<h:commandButton action="#{backingBean.startFlow1()}" value="Flow 1" />
</h:form>
flow1.xhtml:
<h:form>
Hi this is page 1.
<h:inputText label="Enter something:" value="#{flowScope.testOutput}"/><br/>
Request parameter: #{flowScope.testInput}<br/>
<h:commandButton action="returnFromFlow1"/>
</h:form>
BackingBean:
public void startFlow1() {
if (!permissionGranted) {
// show "permission denied"
return;
}
final FacesContext facesContext = FacesContext.getCurrentInstance();
final Application application = facesContext.getApplication();
// get an instance of the flow to start
final String flowId = "flow1";
final FlowHandler flowHandler = application.getFlowHandler();
final Flow targetFlow = flowHandler.getFlow(facesContext,
"", // definingDocumentId (empty if flow is defined in "faces-config.xml")
flowId);
// get the navigation handler and the view ID of the flow
final ConfigurableNavigationHandler navHandler = (ConfigurableNavigationHandler) application.getNavigationHandler();
final NavigationCase navCase = navHandler.getNavigationCase(facesContext,
null, // fromAction
flowId);
final String toViewId = navCase.getToViewId(facesContext);
// initialize the flow scope
flowHandler.transition(facesContext,
null, // sourceFlow
targetFlow,
null, // outboundCallNode
toViewId); // toViewId
// add the parameter to the flow scope
flowHandler.getCurrentFlowScope()
.put("testInput", "hi there2!");
// navigate to the flow by HTTP GET request
final String outcome = toViewId + "?faces-redirect=true";
navHandler.handleNavigation(facesContext,
null, // from action
outcome);
}
请注意,在这种情况下参数不能添加到按钮中,而必须添加到流程作用域中!另请注意,必须由 而不是 完成对流的重定向,否则流作用域将终止!
另请参阅:
发布于 2014-10-12 04:11:28
如果我没看错的话,您应该能够在JSF-2.2 faces-config schema -config.xml中指定一个<redirect/>
指令。因此,使用以下内容,您应该能够实现重定向:
<navigation-rule>
<from-view-id>/pages/test/test.xhtml</from-view-id>
<navigation-case>
<from-outcome>flow1</from-outcome>
<to-flow-document-id>flow1.xhtml</to-flow-document-id>
<redirect />
</navigation-case>
</navigation-rule>
发布于 2014-11-24 20:42:58
请运行这个例子,我希望它能帮到你。
<navigation-rule>
<navigation-case>
<from-outcome>flow1</from-outcome>
<to-view-id>flow1.xhtml</to-view-id>
<redirect></redirect>
</navigation-case>
</navigation-rule>
https://stackoverflow.com/questions/23745606
复制相似问题