Mojarra 2.1.14 flash scope messages and redirect to different path

安稳与你 提交于 2019-12-08 01:22:44

问题


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 :) )


回答1:


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

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.

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

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>

See also:

  • JSF - Keep Faces Messages after redirect from @PostConstruct
  • Adding faces message to redirected page using ExternalContext.redirect()


来源:https://stackoverflow.com/questions/12723100/mojarra-2-1-14-flash-scope-messages-and-redirect-to-different-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!