Java 怎么生成JSF错误消息

2019年8月13日22:14:11Java 怎么生成JSF错误消息已关闭评论 125 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";
        error(summary);
    }
    
    public static void error(String summary) {
        error(summary, null, null);
    }
    
    public static void error(String summary, String detail) {
        error(summary, detail, null);
    }
    
    public static void error(UIComponent component, String summary) {
        error(summary, null, component);
    }
    
    public static void error(String summary, String detail,
            UIComponent component) {
        message(summary, detail, component, FacesMessage.SEVERITY_ERROR);
    }
    
    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);
        }
    }
}

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