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

3.8k Views Asked by At

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.

1

There are 1 best solutions below

1
On BEST ANSWER

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));
}