Question

I want to implement activation link via servlet or JAX-RS (not important which one), and later redirect user to proper page leaving him a FacesMessage stored in Flash. I have no problem with redirection itself, however I don't know how to access Flash.

Was it helpful?

Solution

You can obtain access to the Flash object from the ExternalContext:

  1. Obtain access to the Flash:

    Flash flash = FacesContext.getCurrentInstance().getExternalContext().getFlash();
    
  2. Set keepMessages =true on the object, to ensure that the FacesMessage you store in it survives the redirect

    flash.setKeepMessages(true);
    
  3. Store your FacesMessages using the putNow method, to ensure that even after the redirect, the messages will survive at least one page refresh

    flash.putNow(yourFacesMessage);
    

You really don't need to store the FacesMessage in the flash object itself; queuing them in the FacesContext is enough to guarantee that they'll be available on the other page

Related:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top