Search code examples
jsfprimefacesicefaces

Flash scoped variable getting expired


I am passing a value from page 1 => page 2 using flash scoped variable.
After reaching the page 2 it is able to show the variable for first time.
When I reload the page the flash variable goes null.
Is there any way to retain the flash variable in page2 for the view scope?


Solution

  • But you can keep a flash scoped variable in backing bean of page 2 as

    String myFlashVar;
    @PostConstruct     
    public void init() {         
       myFlashVar= FacesContext.getCurrentInstance().getExternalContext().getFlash().get("flashkey"‌​). toString();     
    }
    

    Alternative way is

    @ManagedProperty("#{flash}")   
    private Flash flash;//then you can access it as flash.get("flashkey")
    

    You may also consider @ViewScoped.