Show success message and then redirect to another page after a timeout using PageFlow

后端 未结 3 643
旧巷少年郎
旧巷少年郎 2021-02-14 19:46

How can I show a success message and then redirect the user to another page after a timeout of e.g. 5 seconds?

I need this for the login page after a successful login. I

3条回答
  •  深忆病人
    2021-02-14 20:34

    It is one of the utilities of Flash. Instead of

    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"Sample info message", "PrimeFaces rocks!"));:
    

    simply use this code

    FacesContext facesContext = FacesContext.getCurrentInstance();
    Flash flash = facesContext.getExternalContext().getFlash();
    flash.setKeepMessages(true);
    flash.setRedirect(true);
    facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,"Sample info message", "PrimeFaces rocks!"));
    

提交回复
热议问题