All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javax.faces.application.FacesMessage Maven / Gradle / Ivy

There is a newer version: 4.1.0
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package javax.faces.application;

import java.io.Serializable;
import java.util.*;

/**
 *see Javadoc of JSF Specification
 *

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

* *The implementation must take the following steps when creating FacesMessage instances given a messageId:
  • Call * {@link Application.getMessageBundle()}. If non-null, locate the named ResourceBundle, using * the Locale from the current {@linkUIViewRoot} and see if it has a value for the argument * messageId. If it does, treat the value as the summary of the {@link FacesMessage}. If it * does not, or if {@link Application.getMessageBundle()} returned null, look in the ResourceBundle named by the value * of the constant {@link 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 * .
  • * * @author Manfred Geiler (latest modification by $Author: lu4242 $) * @version $Revision: 882395 $ $Date: 2009-11-19 22:15:53 -0500 (Thu, 19 Nov 2009) $ * */ public class FacesMessage implements Serializable { private static final long serialVersionUID = 4851488727794169661L; /** * 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 level indicating an informational message rather than an error. */ public static final FacesMessage.Severity SEVERITY_INFO = new Severity("Info", 1); /** * Message severity level indicating that an error might have occurred. */ public static final FacesMessage.Severity SEVERITY_WARN = new Severity("Warn", 2); /** * Message severity level indicating that an error has occurred. */ public static final FacesMessage.Severity SEVERITY_ERROR = new Severity("Error", 3); /** * Message severity level indicating that a serious error has occurred. */ public static final FacesMessage.Severity SEVERITY_FATAL = new Severity("Fatal", 4); /** * Immutable Lis of valid {@link FacesMessage.Severity}instances, in ascending order of their ordinal * value. */ public static final List VALUES; /** * Immutable Map of valid {@link FacesMessage.Severity}instances, keyed by name. */ public static final Map VALUES_MAP; static { Map map = new HashMap(7); map.put(SEVERITY_INFO.toString(), SEVERITY_INFO); map.put(SEVERITY_WARN.toString(), SEVERITY_WARN); map.put(SEVERITY_ERROR.toString(), SEVERITY_ERROR); map.put(SEVERITY_FATAL.toString(), SEVERITY_FATAL); VALUES = Collections.unmodifiableList(new ArrayList(map.values())); VALUES_MAP = Collections.unmodifiableMap(map); } private FacesMessage.Severity _severity; private String _summary; private String _detail; private boolean _rendered; /** *Construct a new {@link FacesMessage} with no initial values. The severity is set to Severity.INFO. */ public FacesMessage() { _severity = SEVERITY_INFO; _rendered = false; } /** * Construct a new {@link FacesMessage} with just a summary. The detail is null, the severity is set to * Severity.INFO. */ public FacesMessage(String summary) { _summary = summary; _severity = SEVERITY_INFO; _rendered = false; } /** * Construct a new {@link FacesMessage} with the specified initial values. The severity is set to Severity.INFO. * * @param summary * - Localized summary message text * @param detail * - Localized detail message text */ public FacesMessage(String summary, String detail) { _summary = summary; _detail = detail; _severity = SEVERITY_INFO; _rendered = false; } /** * Construct a new {@link FacesMessage}with the specified initial values. * * @param severity * - the severity * @param summary * - Localized summary message text * @param detail * - Localized detail message text */ public FacesMessage(FacesMessage.Severity severity, String summary, String detail) { if (severity == null) throw new NullPointerException("severity"); _severity = severity; _summary = summary; _detail = detail; _rendered = false; } /** * * @return */ public FacesMessage.Severity getSeverity() { return _severity; } /** * Return the severity level. */ public void setSeverity(FacesMessage.Severity severity) { if (severity == null) throw new NullPointerException("severity"); _severity = severity; } /** * Return the localized summary text. */ public String getSummary() { return _summary; } /** * Set the localized summary text. * * @param summary * - The new localized summary text */ public void setSummary(String summary) { _summary = summary; } /** * * @return */ public String getDetail() { if (_detail == null) { // Javadoc: // If no localized detail text has been defined for this message, return the localized summary text instead return _summary; } return _detail; } /** * Set the localized detail text. * * @param detail * - The new localized detail text */ public void setDetail(String detail) { _detail = detail; } public static class Severity implements Comparable { private String _name; private int _ordinal; private Severity(String name, int ordinal) { _name = name; _ordinal = ordinal; } public int getOrdinal() { return _ordinal; } @Override public String toString() { return _name; } public int compareTo(Object o) { return getOrdinal() - ((Severity)o).getOrdinal(); } } public boolean isRendered() { return _rendered; } public void rendered() { this._rendered = true; } }




    © 2015 - 2025 Weber Informatics LLC | Privacy Policy