Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * $Id: FacesMessage.java,v 1.21 2007/07/31 16:42:08 rlubke Exp $
   */
  
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   * 
   * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
   * 
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
  * and Distribution License("CDDL") (collectively, the "License").  You
  * may not use this file except in compliance with the License. You can obtain
  * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
  * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
  * language governing permissions and limitations under the License.
  * 
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
  * Sun designates this particular file as subject to the "Classpath" exception
  * as provided by Sun in the GPL Version 2 section of the License file that
  * accompanied this code.  If applicable, add the following below the License
  * Header, with the fields enclosed by brackets [] replaced by your own
  * identifying information: "Portions Copyrighted [year]
  * [name of copyright owner]"
  * 
  * Contributor(s):
  * 
  * If you wish your version of this file to be governed by only the CDDL or
  * only the GPL Version 2, indicate your decision by adding "[Contributor]
  * elects to include this software in this distribution under the [CDDL or GPL
  * Version 2] license."  If you don't indicate a single choice of license, a
  * recipient has the option to distribute your version of this file under
  * either the CDDL, the GPL Version 2 or to extend the choice of license to
  * its licensees as provided above.  However, if you add GPL Version 2 code
  * and therefore, elected the GPL Version 2 license, then the option applies
  * only if the new code is made subject to such option by the copyright
  * holder.
  */
 
 package javax.faces.application;
 
 
 
 import java.util.List;
 import java.util.Map;

FacesMessage represents a single validation (or other) message, which is typically associated with a particular component in the view. A FacesMessage instance may be created based on a specific messageId. The specification defines the set of messageIds for which there must be FacesMessage instances.

The implementation must take the following steps when creating FacesMessage instances given a messageId:

    Call Application.getMessageBundle(). If non-null, locate the named ResourceBundle, using the Locale from the current javax.faces.component.UIViewRoot and see if it has a value for the argument messageId. If it does, treat the value as the summary of the FacesMessage. If it does not, or if Application.getMessageBundle() returned null, look in the ResourceBundle named by the value of the constant FACES_MESSAGES and see if it has a value for the argument messageId. If it does, treat the value as the summary of the FacesMessage. If it does not, there is no initialization information for the FacesMessage instance.

    In all cases, if a ResourceBundle hit is found for the {messageId}, look for further hits under the key {messageId}_detail. Use this value, if present, as the detail for the returned FacesMessage.

    Make sure to perform any parameter substitution required for the summary and detail of the FacesMessage.

 
 
 public class FacesMessage implements Serializable {
 
 
     // --------------------------------------------------------------- Constants
 

    

ResourceBundle identifier for messages whose message identifiers are defined in the JavaServer Faces specification.

    public static final String FACES_MESSAGES = "javax.faces.Messages";
    // ------------------------------------------------- Message Severity Levels
    // Any new Severity values must go at the end of the list, or we will break
    // backwards compatibility on serialized instances
    private static final String SEVERITY_INFO_NAME = "INFO";
    

Message severity level indicating an informational message rather than an error.

    public static final Severity SEVERITY_INFO = 
    private static final String SEVERITY_WARN_NAME = "WARN";
    

Message severity level indicating that an error might have occurred.

    public static final Severity SEVERITY_WARN = 
    private static final String SEVERITY_ERROR_NAME = "ERROR";
    

Message severity level indicating that an error has occurred.

    public static final Severity SEVERITY_ERROR = 
    private static final String SEVERITY_FATAL_NAME = "FATAL";
    

Message severity level indicating that a serious error has occurred.

    public static final Severity SEVERITY_FATAL = 

Array of all defined values, ascending order of ordinal value. Be sure you include any new instances created above, in the same order.

    private static final Severity[] values =
    {  };
    

    

Immutable List of valid FacesMessage.Severity instances, in ascending order of their ordinal value.

    public static final List VALUES = 
	Collections.unmodifiableList(Arrays.asList());
    private static Map<String,Severity_MODIFIABLE_MAP =
         new HashMap<String,Severity>(4, 1.0f);
    
    static {
	for (int i = 0, len = .i < leni++) {
	}
    }
    

    

Immutable Map of valid FacesMessage.Severity instances, keyed by name.

    public final static Map VALUES_MAP = 
    
    private static final long serialVersionUID = -1180773928220076822L;
    
    // ------------------------------------------------------------ Constructors


    

Construct a new FacesMessage with no initial values. The severity is set to Severity.INFO.

    public FacesMessage() {
        super();
    }

    

Construct a new FacesMessage with just a summary. The detail is null, the severity is set to Severity.INFO.

    public FacesMessage(String summary) {
        super();
        setSummary(summary);
    }




    

Construct a new FacesMessage with the specified initial values. The severity is set to Severity.INFO.

Parameters:
summary Localized summary message text
detail Localized detail message text
Throws:
java.lang.IllegalArgumentException if the specified severity level is not one of the supported values
    public FacesMessage(String summaryString detail) {
        super();
        setSummary(summary);
        setDetail(detail);
    }


    

Construct a new FacesMessage with the specified initial values.

Parameters:
severity the severity
summary Localized summary message text
detail Localized detail message text
Throws:
java.lang.IllegalArgumentException if the specified severity level is not one of the supported values
    public FacesMessage(Severity severityString summary
			String detail) {
        super();
	setSeverity(severity);
        setSummary(summary);
        setDetail(detail);
    }
    // ------------------------------------------------------ Instance Variables
    private String summary = null;
    private String detail = null;
    // ---------------------------------------------------------- Public Methods


    

Return the localized detail text. If no localized detail text has been defined for this message, return the localized summary text instead.

    public String getDetail() {
	if (this. == null) {
	    return (this.);
else {
	    return (this.);
	}
    }


    

Set the localized detail text.

Parameters:
detail The new localized detail text
    public void setDetail(String detail) {
        this. = detail;
    }


    

Return the severity level.

    public Severity getSeverity() {
        return (this.);
    }


    

Set the severity level.

Parameters:
severity The new severity level
Throws:
java.lang.IllegalArgumentException if the specified severity level is not one of the supported values
    public void setSeverity(Severity severity) {
        if ((severity.getOrdinal() < .getOrdinal()) || 
	    (severity.getOrdinal() > .getOrdinal())) {
            throw new IllegalArgumentException(String.valueOf(severity));
        }
        this. = severity;
    }


    

Return the localized summary text.

    public String getSummary() {
        return (this.);
    }


    

Set the localized summary text.

Parameters:
summary The new localized summary text
    public void setSummary(String summary) {
        this. = summary;
    }

    

Persist FacesMessage artifacts, including the non serializable Severity.

    private void writeObject(ObjectOutputStream outthrows IOException {
        out.writeInt(getSeverity().getOrdinal());
        out.writeObject(getSummary());
        out.writeObject(getDetail());
    }

    

Reconstruct FacesMessage from serialized artifacts.

    private void readObject(ObjectInputStream in)
        throws IOExceptionClassNotFoundException {
         = ;
         = null;
         = null;
        int ordinal = in.readInt();
        if (ordinal == .getOrdinal()) {
            setSeverity(.);
        } else if (ordinal == .getOrdinal()) {
            setSeverity(.);
        } else if (ordinal == .getOrdinal()) {
            setSeverity(.);
        } else if (ordinal == .getOrdinal()) {
            setSeverity(.);
        }
        setSummary((String)in.readObject());
        setDetail((String)in.readObject());
    }

    

Class used to represent message severity levels in a typesafe enumeration.

    public static class Severity implements Comparable {
	// -------------------------------------------------------  Constructors

Private constructor to disable the creation of new instances.

	private Severity(String newSeverityName) {
	     = newSeverityName;
	}
	// -------------------------------------------------- Instance Variables

The ordinal value assigned to this instance.

	private final int ordinal = ++;


The (optional) name for this severity.

        String severityName = null;
	// -----------------------------------------------------  Public Methods

Compare this FacesMessage.Severity instance to the specified one. Returns a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object.

Parameters:
other The other object to be compared to
	public int compareTo(Object other) {
	    return this. - ((Severityother).;
	}


Return the ordinal value of this FacesMessage.Severity instance.

	public int getOrdinal() {
	    return (this.);
	}


Return a String representation of this FacesMessage.Severity instance.

	public String toString() {
	    if (null == ) {
		return (String.valueOf(this.));
	    }
	    return (String.valueOf(this.) + ' ' + this.);
	}
	// ---------------------------------------------------  Static Variables

Static counter returning the ordinal value to be assigned to the next instance that is created.

	private static int nextOrdinal = 0;
    }
New to GrepCode? Check out our FAQ X