0

I have a Java EE app where I use JSF2 + PrettyFaces + EBJ3 + Glassfish

I just recently updated to Glassfish4 which is the default Server implementation for Java EE 7 and I started getting issues with PrettyFaces.

I have configured on my faces-config.xml:

<lifecycle>
  <phase-listener>com.ocpsoft.pretty.faces.event.MultiPageMessagesSupport</phase-listener>
</lifecycle>     

to enable for Faces Messages to be passed around correctly and displayed on screen.

But since I upgraded from Glassfish3 to 4 I started getting this issue:

java.lang.IllegalStateException: Cannot create a session after the response has been committed ...

        at com.ocpsoft.pretty.faces.util.FacesMessagesUtils.saveMessages(FacesMe
ssagesUtils.java:56)
        at com.ocpsoft.pretty.faces.event.MultiPageMessagesSupport.afterPhase(Mu
ltiPageMessagesSupport.java:66)

If I remove the listener from faces-config.xml none of the Faces messages are displayed on screen.

I am using PrettyFaces to have nice well formatted URLs to enhance SEO on my site. I wish I couldn't have to replace it or refactor my app to not use it since I already mapped a lot of the navigation flow using it. Does somebody know a better option for this scenario? I really appreciate any suggestions. Thanks.

guilhebl
  • 8,330
  • 10
  • 47
  • 66
  • I'm no expert in PrettyFaces but tweaking the [state saving method](http://stackoverflow.com/q/8471551/1530938) may help to workaround the issue. GF4 ships with JSF2.2, which has not been officially released, so this is a bug(or some incompatibility) in there somewhere. – kolossus Jun 22 '13 at 21:47

1 Answers1

1

I don't recommend to use MultiPageMessagesSupport if you are deploying to a "modern" container with JSF 2.2 support. The MultiPageMessagesSupport phase listener has been developed for JSF 1.x. JSF 2.x added support for persisting messages across redirects. Just execute this code before redirecting:

FacesContext.getCurrentInstance().getExternalContext().getFlash().setKeepMessages(true);
chkal
  • 5,598
  • 21
  • 26
  • Well then I would have to place this line of code before every JSF navigation case returning "pretty:" or "pretty:something"? – guilhebl Jun 25 '13 at 03:33
  • Yes, or you could write a PhaseListener that calls this method on every request after RESTORE_VIEW or something like that. To be honest, I'm not sure what the common practice for this is. I for myself have a Messages helper class I use to queue message which always sets this flag after adding a message to the queue. – chkal Jun 25 '13 at 08:44