问题
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 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));
}
来源:https://stackoverflow.com/questions/10366395/set-flash-keepmessage-to-true-in-jsf-2-configuration-file-is-possible