重定向后 Flash 范围内的对象不可用 [英] Object in Flash scope is not available after redirect

查看:14
本文介绍了重定向后 Flash 范围内的对象不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对在 jsf 2 中使用 flash 范围有误解.我想在我的操作过程中将一个对象放入 flash map,并在下一页中显示该对象.这是我的操作(由 h:commandLink 调用):

I have a misunderstanding with the use of flash scope in jsf 2. I want to put an object in flash map during my action and show this object in the next page. Here is my action (call by h:commandLink):

public String showDetail(PersonneDTO personne) {
    MessageFlashBean message = new MessageFlashBean();
    message.addMessage("test");
    FacesContext.getCurrentInstance().getExternalContext().getFlash()
        .put("test", message);
    return "showDetail";
}

这只是一个测试,但我要使用的真实对象更复杂.

It's just a test, but the real object I want to use is more complex.

这是使用 flash 的第二页:

Here is the second page with the flash use:

<ui:fragment rendered="#{flash.test != null and flash.test.hasMessage()}" >
    <ui:repeat var="message" value="#{flash.test.messages}">
        #{message}
    </ui:repeat>
</ui:fragment>

这是导航(这是我的问题:)):

Here is the navigation (and here is my problem :) ):

<navigation-rule>
    <from-view-id>/index.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>showDetail</from-outcome>
        <to-view-id>/private/showDetail.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

在这种情况下,闪光灯可以正常工作并且显示我的消息.

In this case, the flash scope works fine and my message appears.

但是如果我在导航案例中添加重定向,我在闪图上的对象就消失了.

But if I add a redirect in the navigation case, my object in the flash map has disappeared.

我不明白为什么我不能在导航规则中使用重定向(我认为这是 flash 范围的目标).

I don't understand why I can't use redirect in the navigation rule (I believed it was the goal of flash scope).

可能是我的代码有问题.

May be something is wrong in my code.

有人可以帮助我吗?

谢谢

推荐答案

Mojarra 对 JSF2 Flash 范围的实现 有很多问题.大多数问题都在每个新的 Mojarra 版本中得到解决.目前,使用最新的 Mojarra 版本,即 2.1.6,据我所知,仍然只有一个主要的未解决问题:它不会如果您重定向到不同的基本路径,则不起作用.另请参阅 issue 1751 中长时间讨论中的(当前)最后一条评论.

The Mojarra's implementation of the JSF2 Flash scope had a lot of problems. Most of them were resolved with every new Mojarra release. Currently, with the latest Mojarra version, the 2.1.6, there's as far as I know still only one major open problem: it won't work if you redirect to a different base path. See also the (currently) last comment in the long discussion in issue 1751.

现在,您基本上有以下选择:

Right now, you have basically the following options:

  1. 当您需要重定向到不同的基本路径时,请忘记使用 Flash.改用请求参数或尝试使用自定义 cookie 模拟 Flash 范围.

  1. Forget using Flash when you need to redirect to a different base path. Use a request parameter instead or try to simulate the flash scope with a custom cookie.

如果可能,请重新组织文件夹结构,以便在需要 Flash 范围继续存在时无需重定向到不同的基本路径.

If possible, reorganize the folder structure so that you don't need to redirect to a different base path when you need the flash scope to survive.

尝试 MyFaces 而不是 Mojarra.也许它在闪光范围方面做得更好.

Try MyFaces instead of Mojarra. Maybe it does it better with regard to flash scope.

<小时>

更新:根据issue 2136,Flash scope最后一个未解决的问题在即将推出的 Mojarra 2.1.14 中解决了在不同路径上重定向后不可用的问题.因此,在此版本中,所有 Flash 范围相关问题已发现并已打开应该解决并关闭.


Update: as per issue 2136, the last open problem of Flash scope not being available after a redirect on a different path is solved in the shortly upcoming Mojarra 2.1.14. So with this version, all Flash scope related problems discovered and open so far should be solved and closed.

这篇关于重定向后 Flash 范围内的对象不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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