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

br.com.jhonsapp.util.jsf.message.MessageFacesUtil Maven / Gradle / Ivy

Go to download

This project provides useful classes that facilitate the construction of new components web.

The newest version!
package br.com.jhonsapp.util.jsf.message;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

/**
 * Class responsible for manipulating messages from the message archive.
 * 
 * @author Jhonathan Camacho
 *
 */
public class MessageFacesUtil {

	/**
	 * Adds a message in error format.
	 * 
	 * @param key
	 *            the key that identifies the message.
	 * 
	 */
	public static void addErrorMessage(String key) {

		String message = getMessage(key);

		FacesContext.getCurrentInstance().addMessage(null,
				new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message));
	}

	/**
	 * Adds a message in information format.
	 * 
	 * @param key
	 *            the key that identifies the message.
	 * 
	 */
	public static void addInfoMessage(String key) {

		String message = getMessage(key);

		FacesContext.getCurrentInstance().addMessage(null,
				new FacesMessage(FacesMessage.SEVERITY_INFO, message, message));
	}

	/**
	 * Gets the message from the message file.
	 * 
	 * @param key
	 *            the key that identifies the message.
	 * @return the message.
	 */
	public static String getMessage(String key) {
		FacesContext facesContext = FacesContext.getCurrentInstance();
		String msg = facesContext.getApplication().getResourceBundle(facesContext, "translation").getString(key);
		return msg;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy