package controller;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


import java.io.Serializable;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

/**
 *
 * @author Patrick
 */
public abstract class AbstractController implements Serializable{
	private static final long serialVersionUID = -5908716187853409719L;

	protected void sendInfoMessage(String title, String message){
        FacesMessage facesMessage = new FacesMessage(
                FacesMessage.SEVERITY_INFO, title, message);
        addMessage(facesMessage);
    }
    
    protected void sendWarnMessage(String title, String message){
        FacesMessage facesMessage = new FacesMessage(
                FacesMessage.SEVERITY_WARN, title, message);
        addMessage(facesMessage);
    }
    
    protected void sendErrorMessage(String title, String message){
        FacesMessage facesMessage = new FacesMessage(
                FacesMessage.SEVERITY_ERROR, title, message);
        addMessage(facesMessage);
    }
    
    protected void sendFatalMessage(String title, String message){
        FacesMessage facesMessage = new FacesMessage(
                FacesMessage.SEVERITY_FATAL, title, message);
        addMessage(facesMessage);
    }
    
    private void addMessage(FacesMessage message) {
        FacesContext.getCurrentInstance().addMessage(null, message);
    }
    
    protected void errorMessage() {
        String title = "Fehler!";
        String info = "Es ist ein Fehler aufgetreten, bitte versuchen Sie es erneut!";
        sendErrorMessage(title, info);
    }
}
