JSF warn message - Java JSF

Java examples for JSF:Message

Description

JSF warn message

Demo Code

/**/*from w ww  .ja  v  a 2s  . c  o  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";
        warn(summary);
    }
    /**
     * @param summary summary text
     */
    public static void warn(String summary) {
        warn(summary, null, null);
    }
    /**
     * @param summary summary text
     */
    public static void warn(String summary, String detail) {
        warn(summary, detail, null);
    }
    /**
     * @param component associated <code>UIComponent</code>
     * @param summary summary text
     */
    public static void warn(UIComponent component, String summary) {
        warn(summary, null, component);
    }
    /**
     * @param summary summary text
     */
    public static void warn(String summary, String detail,
            UIComponent component) {
        message(summary, detail, component, FacesMessage.SEVERITY_WARN);
    }
    /**
     * @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