javajsfjsf-2messageflash-scope

set Flash.keepMessage to true in JSF 2 configuration file is possible?


This line:

FacesContext.getCurrentInstance().getExternalContext().getFlash().setKeepMessages(true);

Can be changed by another code in any configuration files? I want to avoid typing this line whenever I need to redirect from code whit this line:

     FacesContext.getCurrentInstance().getExternalContext().redirect("errorApp");

Regards.


Solution

  • There is no configuration setting to change the "keep messages" feature.

    Just create an utility method which replaces the repeated code by a single method call. E.g.

    public static void addGlobalInfoFlashMessage(String message) {
        FacesContext context = FacesContext.getCurrentInstance();
        context.getExternalContext().getFlash().setKeepMessages(true);
        context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, message, null));
    }