重定向后,Flash作用域中的对象不可用 [英] Object in Flash scope is not available after redirect

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

问题描述

我对在jsf 2中使用Flash作用域有误解. 我想在执行操作时将一个对象放入Flash映射中,然后在下一页中显示该对象. 这是我的操作(通过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.

但是,如果我在导航案例中添加了重定向,则Flash地图中的对象将消失.

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版本(即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.请改用request参数,或尝试使用自定义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范围的最后一个未解决的问题在不久之后的 Mojarra 2.1.14 中,解决了在其他路径上重定向后无法使用的问题.因此,使用此版本,到目前为止,发现并打开了 all 与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天全站免登陆