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

醉酒当歌 提交于 2019-12-25 08:02:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!