Mojarra 2.1.14 flash messages and redirects to another path

According to this: http://java.net/jira/browse/JAVASERVERFACES-2136 flash messages with advanced features must survive redirecting to the page in a different way. I wanted to use something similar in my application, so I uploaded a snapshot of javax.faces-2.1.14-20121003.074348-10 https://maven.java.net/content/repositories/snapshots/org/glassfish/javax.faces/ 2.1.14-SNAPSHOT / for testing.

My situation is this: I have a page (call it test.xhtml) in the root directory, which in the backup bean during the constructor call checks and conditionally sets the message using Omnifaces Message.addFlashGlobalInfo and redirects to index.xthml also in the root directory using Omnifaces Faces.Redirect() (thanks to BalusC!). In index.xhtml I have Primefaces

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

I use the same “configuration” described above on other pages, and works fine when redirecting on the same page as the bean method.

So shouldn't the message go through a different redirect path, or have I misunderstood something about this problem? maybe something is wrong here?

Thanks in advance! (I look forward to hearing from BalusC about this btw :))

+2
source share
1 answer

I just used the init method, which sets the message and redirects, but the message does not appear again! so I don’t think PostConstruct will work either.

In fact, <f:event type="preRenderView"> too late to set a flash message. The flash area cannot be created when the JSF is currently in the render response phase. You need to set the flash message before the render response phase. Despite the name preRenderView , this event actually fires during the (very beginning) phase of the rendering response.

@PostConstruct can be on time, provided that it was not called during the render response. This, however, does not work very well with <f:viewParam> .

To fix this, since you are already using OmniFaces, 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:

+3
source

All Articles