package org.ajax4jsf.bean;

import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

public class MessageBean2 implements Validator{
	
	private String string;
	
	private Boolean rendered;

	private Boolean showDetail;

	private Boolean showSummary;

	private Boolean ajaxRendered;
	
	public MessageBean2() {
		init();
	}
	
	public void init() {
		string = "something";
		rendered = true;
		showDetail = true;
		showSummary = false;
		ajaxRendered = false;
	}
	
	public void validate(FacesContext context, UIComponent component,
			Object value) throws ValidatorException {
		Severity severity = null;
		if ("fatal".equals(value)) {
			severity = FacesMessage.SEVERITY_FATAL;			
		} else if ("error".equals(value)) {
			severity = FacesMessage.SEVERITY_ERROR;			
		} else if ("warn".equals(value)) {
			severity = FacesMessage.SEVERITY_WARN;			
		} else if ("info".equals(value)) {
			severity = FacesMessage.SEVERITY_INFO;			
		}
		if (severity != null) {
			throw new ValidatorException(new FacesMessage(severity,
					"messageSummary", "messageDetail"));
		}
	}

	public void setString(String string) {
		this.string = string;
	}

	public String getString() {
		return string;
	}

	public void setRendered(Boolean rendered) {
		this.rendered = rendered;
	}

	public Boolean getRendered() {
		return rendered;
	}

	public void setShowDetail(Boolean showDetail) {
		this.showDetail = showDetail;
	}

	public Boolean getShowDetail() {
		return showDetail;
	}

	public void setShowSummary(Boolean showSummary) {
		this.showSummary = showSummary;
	}

	public Boolean getShowSummary() {
		return showSummary;
	}

	public void setAjaxRendered(Boolean ajaxRendered) {
		this.ajaxRendered = ajaxRendered;
	}

	public Boolean getAjaxRendered() {
		return ajaxRendered;
	}
	
}
