钻嘴鱼科2.1.14闪光范围消息和重定向到不同的路径(Mojarra 2.1.14 flash sc

2019-09-23 12:10发布

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.

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" />

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??

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

Answer 1:

我只是用来打电话,做套消息和重定向,但再次出现没有消息的init方法! 所以我不认为PostConstruct要么工作..

实际上, <f:event type="preRenderView">太晚设置闪光消息。 当JSF正坐在那渲染响应阶段无法创建闪光范围。 你基本上需要之前设定闪光消息呈现响应阶段。 尽管名字preRenderView ,这一事件实际上是 (一开始)发射呈现响应阶段。

@PostConstruct 可能是时间上的,只要它被调用时渲染响应。 然而,这不会一起工作得很好<f:viewParam>

为了解决这个问题,因为你正在使用OmniFaces已经,只是使用<f:event type="postInvokeAction">

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

也可以看看:

  • JSF -保持面消息从@PostConstruct重定向后
  • 添加面消息使用ExternalContext.redirect到重定向页面()


文章来源: Mojarra 2.1.14 flash scope messages and redirect to different path