Show FacesMessage after redirection from servlet or JAX-RS using Flash

StackOverflow https://stackoverflow.com/questions/23395290

  •  12-07-2023
  •  | 
  •  

문제

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.

도움이 되었습니까?

해결책

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:

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top