0
 Flash flash = FacesContext.getCurrentInstance().getExternalContext().getFlash();
 flash.setKeepMessages(true);
 getJsfContext().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_INFO, "My message.", ""));

 getJsfContext().getExternalContext().redirect("index.xhtml");

This is my backing bean. I want to store messages to flash and display it after redirect. This doesn't work. Nothing happens. What is the solution?

getJsfContext() is my function to get FacesContext.getCurrentInstance()

Tiny
  • 27,221
  • 105
  • 339
  • 599
user2950593
  • 9,233
  • 15
  • 67
  • 131
  • Where do store messages into `Flash`? (Or you might be experiencing a bug with `Flash` in certain circumstances). – Tiny Jan 07 '15 at 09:11
  • It seems after your comment that I don't store it to flash at all.What to add to my code to store it? – user2950593 Jan 07 '15 at 09:12
  • Which JSF impl/version? Older Mojarra versions have had a lot of trouble with flash. To exclude them all, make sure you're using most recent version. – BalusC Jan 07 '15 at 09:16
  • `flash.put(String key, Object message);` to store messages and on the receiver side you get a message associated with a certain key using `flash.get(Object key)`. You might encounter a message something like this, "*WARNING: JSF1095: The response was already committed by the time we tried to set the outgoing cookie for the flash. Any values stored to the flash will not be available on the next request.*" I faced while using `Flash` on JSF 2.2.7. – Tiny Jan 07 '15 at 09:28
  • "JSF 2.2" is the spec version. I was asking for implementation and its version. E.g. "Mojarra 2.2.9" or "MyFaces 2.2.6". By the way, @Tiny makes a good point about the warning. This can indeed happen if you're performing the job during render response phase instead of invoke action phase. Have you read the server logs? – BalusC Jan 07 '15 at 09:39
  • Use a PhaseListener, as outlined in this answer: http://stackoverflow.com/questions/10595760/adding-faces-message-to-redirected-page-using-externalcontext-redirect – Fuzzy Analysis Mar 23 '15 at 04:35

0 Answers0