如何使用faces-redirect输入JSF 2.2流程

Jon*_*n B 9 jsf post-redirect-get jsf-2.2 faces-flow

我有一个基本的流程示例工作:

src/main/webapp
|
|- index.xhtml
|- flow1
   |- flow1-flow.xml
   |- flow1.xhtml
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

flow1.xhtml显示参数,并允许您在流范围中输入值:

<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>
Run Code Online (Sandbox Code Playgroud)

flow1-flow.xml只将返回节点定义为"returnFromFlow1"并将其设置为/index.xhtml.

这似乎有效.我想在输入流时实现post-redirect-get,以便浏览器地址栏与视图保持同步.所以我自然尝试了action ="flow1?faces-redirect = true".此更改阻止流程执行..它只是在单击按钮时重新加载index.xhtml.

然后我尝试了action ="flow1/flow1.xhtml?faces-redirect = true".这会加载页面并按预期重定向,但流程未初始化.当我在流程中提交表单时,我收到有关flowScope解析为null的错误.

做了一点研究,我找到了一个提示,设置"to-flow-document-id"来强制它初始化流程.所以我添加到我的命令按钮.没变.

有关如何实现这一目标的任何想法?

kol*_*sus 0

好吧,如果我正确阅读JSF-2.2 faces-config 模式,您应该能够<redirect/>faces-config.xml中指定指令。因此,使用以下内容,您应该能够实现重定向:

       <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>
Run Code Online (Sandbox Code Playgroud)