Java 怎么生成JSF致命消息

2019年8月13日22:15:43Java 怎么生成JSF致命消息已关闭评论 250 1042字阅读3分28秒

1.简介

Java 怎么生成JSF致命消息?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */

 
import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.apache.log4j.Logger;

public class Main{
    public static void main(String[] argv) throws Exception{
        String summary = "tah1986.com";
        fatal(summary);
    }
    
    public static void fatal(String summary) {
        fatal(summary, null, null);
    }
    
    public static void fatal(String summary, String detail) {
        fatal(summary, detail, null);
    }
    
    public static void fatal(UIComponent component, String summary) {
        fatal(summary, null, component);
    }
    
    public static void fatal(String summary, String detail,
            UIComponent component) {
        message(summary, detail, component, FacesMessage.SEVERITY_FATAL);
    }
    
    public static void message(String summary, String detail,
            UIComponent component, Severity severity) {
        FacesMessage fm = new FacesMessage(severity, summary, detail);
        if (component == null) {
            FacesContext.getCurrentInstance().addMessage(null, fm);
        } else {
            FacesContext.getCurrentInstance().addMessage(component.getId(),
                    fm);
        }
    }
}

 
继续阅读
编程十万个怎么办