Mojarra 2.1.14 Flash作用域消息并重定向到其他路径 [英] Mojarra 2.1.14 flash scope messages and redirect to different path

查看:158
本文介绍了Mojarra 2.1.14 Flash作用域消息并重定向到其他路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据此: http://java.net/jira/browse/JAVASERVERFACES-2136 flash-作用域"消息应在重定向到其他路径上的页面后仍然可以保留..我想在我的应用程序中使用类似的内容,因此我从此处下载了javax.faces-2.1.14-20121003.074348-10快照 https://maven.java. net/content/repositories/snapshots/org/glassfish/javax.faces/2.1.14-SNAPSHOT/进行测试.

According to this: http://java.net/jira/browse/JAVASERVERFACES-2136 flash-"scoped" messages should survive a redirect to a page on a different path.. I wanted to use something like this in my application so i downloaded javax.faces-2.1.14-20121003.074348-10 snapshot from here https://maven.java.net/content/repositories/snapshots/org/glassfish/javax.faces/2.1.14-SNAPSHOT/ to test.

我的情况是这样的:我在根目录中有一个页面(称为test.xhtml),该页面在构造函数调用期间在视野范围内的后备Bean中进行检查并有条件地使用Omnifaces Message.addFlashGlobalInfo设置一条消息.并使用Omnifaces Faces.Redirect()也在根目录中重定向到index.xthml(感谢BalusC!).在index.xhtml中,我有一个Primefaces

My situation is this: I have a page (call it test.xhtml) in the root directory that in the view-scoped backing bean during the call of the constructor does a check and conditionally sets a message using Omnifaces Message.addFlashGlobalInfo and redirects to index.xthml also in the root directory using Omnifaces Faces.Redirect() (thanks BalusC!). In index.xhtml i have a Primefaces

<p:messages id="msg" showDetail="false" autoUpdate="true" />

我在其他页面中也使用了与上述相同的配置",当重定向到称为bean方法的同一页面时,它可以正常工作.

I use the same "configuration" described above in other pages as well and it works fine when the redirect is done to the same page called the bean method.

因此,该消息是否应该在不同的路径重定向中幸免,或者我是否对这个问题有所误解?也许这里还有其他问题?

So shouldn't the message survive the different path redirect or did i misunderstood something about this issue?? maybe there is something else wrong here??

提前谢谢! (我很期待听到有关此问题的BalusC意见:))

Thanks in advance! (i'm looking forward hearing BalusC opinion on this btw :) )

推荐答案

我只是用来调用一个init方法,该方法确实设置了消息并进行了重定向,但再次没有消息出现!所以我也不认为PostConstruct也可以.

i just used to call an init method that does sets message and redirects but again no message appears!! so i don't think PostConstruct will work either..

的确,<f:event type="preRenderView">为时已晚,无法设置即时消息.当JSF当前处于渲染响应阶段时,无法创建Flash作用域.基本上,您需要在呈现响应阶段之前 设置Flash消息.尽管名称为preRenderView,但实际上在渲染响应阶段的 期间(开始)触发了此事件.

Indeed, the <f:event type="preRenderView"> is too late to set a flash message. The flash scope can't be created when JSF is currently sitting in render response phase. You basically need to set the flash message before render response phase. In spite of the name preRenderView, this event is actually fired during (the very beginning of) the render response phase.

@PostConstruct 可能是准时的,只要在渲染响应期间未调用 即可.但是,这不能与<f:viewParam>一起很好地工作.

The @PostConstruct may be on time, provided that it's not been called during render response. This however won't work very well together with <f:viewParam>.

要解决此问题,因为您已经在使用OmniFaces,只需使用 <f:event type="postInvokeAction">

To fix this, as you're using OmniFaces already, just use <f:event type="postInvokeAction">.

<f:metadata>
    <f:viewParam name="some" value="#{bean.some}" />
    <f:event type="postInvokeAction" listener="#{bean.init}" />
</f:metadata>

另请参见:

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