退出JSF流 [英] Exiting a JSF Flow

查看:113
本文介绍了退出JSF流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用JSF Flow,在阅读了一些示例和规范后,我开始使用它了.

I'm starting to use JSF Flows, and after reading some examples and the specs, I got it to work.

我正在使用目录中的打包流方法,如

I'm using the Packaging Flows in Directories method, as described in section 11.4.3.3 of the specification. It seems easier and more in line with the naming conventions already adopted since JSF 2.0.

下面是我当前的目录结构.流ID为向导.

Bellow is my current directory structure. The flow id is wizard.

我了解到有一种通过调用返回节点退出流程的概念.

I understand that there is a concept of exiting the flow by calling a return node.

通过上图,您看到我没有返回节点视图.它只是一个向导,有一堆页面可以来回导航,其优点是可以维护我的ManagedBean状态.

You see, by the image above, that I don't have a return node view. It's just a wizard, with a bunch of pages that can be navigated back and forth, with the advantage that my ManagedBean state is maintained.

问题是,我可以导航到应用程序中的任何页面,而JSF仍保持该流程的状态.如果我回到任何向导页面,所有信息仍然存在,这意味着JSF从未删除流范围.

The problem is, I can navigate to any page in my application, and JSF still maintains the state of that flow. If I come back to any of the Wizard pages, all the information is still there, meaning JSF never dropped the flow scope.

我的问题是:

  1. 如果我有一个"finish" commandButton,我如何告诉JSF,当用户单击该按钮时,它应该删除当前流程范围?
  2. 更重要的是,如果我没有返回节点怎么办?如果用户导航到流目录之外的任何视图*,我如何告诉JSF删除流状态? (通过流程"的概念,我认为这已经是标准行为)
  1. If I have a "finish" commandButton, how do I tell JSF that when the user clicks that button, it should drop the current flow scope?
  2. More importantly, what if I don't have a return node? How do I tell JSF to drop the flow state if the user navigates to any view* outside the flow directory? (by the concept of a "flow", I thought this was already standard behavior)

*只需清楚一点,我的意思是另一个 JSF视图(应用程序中的另一页).我知道,如果用户触发了对我的应用程序之外或JSF范围之外的页面的请求,它将无法执行任何操作.

*Just to be clear, I mean another JSF view (another page within my application). I'm aware it can't do anything if the user triggers a request to a page outside my application or outside the JSF scope.

推荐答案

如果用户导航到任何位置,我如何告诉JSF放弃流状态 在流目录之外查看?

How do I tell JSF to drop the flow state if the user navigates to any view outside the flow directory?

JSF无法知道您只是重定向到说" http://google.de ". Bean将驻留在内存中,直到实现决定由于不使用而将其删除.我有一个类似的问题,现在我能想到的就是使用一些JS-Handler,它会在后端触发一些逻辑来结束流程.通常,如果您的浏览器在无法执行此JS代码的情况下崩溃,则无法解决此问题.

JSF has no way of knowing that you simply redirected to say "http://google.de". The bean will reside in memory until the implementation decides it should be removed due to non-usage. I have a similar problem and all I can think of now is to use some JS-Handler which would trigger some logic in the back-end to end the flow. In general case, there is no way of solving this problem if, say, your browser crashes without being able to execute this JS-code.

如果我有一个"finish" commandButton,如何告诉JSF 用户单击该按钮,它应该删除当前的流量范围吗?

If I have a "finish" commandButton, how do I tell JSF that when the user clicks that button, it should drop the current flow scope?

您必须定义所谓的返回节点.我将给您一个配置示例,该示例成功结束了流程:

You have to define so called return node(-s). I'll give you an example of my configuration, which successfully ends the flow:

<?xml version="1.0"?>
<faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
 <application/>

 <flow-definition id="myflow">
    <view id="Page1">
        <vdl-document>/myflow/Page1.xhtml</vdl-document>
    </view>

    <start-node>Page1</start-node>

    <flow-return id="exit">
        <from-outcome>/home.xhtml</from-outcome>
    </flow-return>
</flow-definition>

</faces-config>

您必须确保命令按钮在action属性中返回退出".例如:

You have to make sure your command button returns "exit" in the action attribute. E.g.:

<p:commandButton value="Finish Flow" action="exit"/>

在流程中,每当您通过"action"属性重定向到某个新页面时,请确保将'faces-redirect = true'附加到URL,否则,至少在我的情况下,我会收到无活动上下文"错误.例如.像这样:

Within the flow, whenever you redirect to some new page via "action" attribute, make sure to append 'faces-redirect=true' to the URL, otherwise , at least in my case I get "No active context" error. E.g. like this:

<p:commandButton value="Next Page" action="Page2.xhtml?faces-redirect=true"/>

这篇关于退出JSF流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆