JSF fatal message - Java JSF

Java examples for JSF:Message

Description

JSF fatal message

Demo Code

/**/*from  w ww. j  av a 2 s  .co m*/
 * License: src/main/resources/license/escidoc.license
 */
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 = "java2s.com";
        fatal(summary);
    }
    /**
     * @param summary summary text
     */
    public static void fatal(String summary) {
        fatal(summary, null, null);
    }
    /**
     * @param summary summary text
     */
    public static void fatal(String summary, String detail) {
        fatal(summary, detail, null);
    }
    /**
     * @param component associated <code>UIComponent</code>
     * @param summary summary text
     */
    public static void fatal(UIComponent component, String summary) {
        fatal(summary, null, component);
    }
    /**
     * @param summary summary text
     */
    public static void fatal(String summary, String detail,
            UIComponent component) {
        message(summary, detail, component, FacesMessage.SEVERITY_FATAL);
    }
    /**
     * @param summary summary text
     */
    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);
        }
    }
}

Related Tutorials