package org.ajax4jsf.bean.validation;

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

/**
 * renamed and copied from demo
 */
public class ValidationBean {
	
	static final String INPUT_TEXT = "text";
	
	public static final String STATUS_TEXT = "UPDATE_MODEL";
	
	private String input = INPUT_TEXT;
	
	private String status;

    private User user = new User();

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    private Admin admin = new Admin();

    public Admin getAdmin() {
        return admin;
    }

    public void setAdmin(Admin admin) {
        this.admin = admin;
    }

    public void success() {
        setProgressString(getProgressString() + "(Strored successfully)");
    }

    private String progressString = "Fill the form please";

    public String getProgressString() {
        return progressString;
    }

    public void setProgressString(String progressString) {
        this.progressString = progressString;
    }

    public void storeOrderOfDay(ActionEvent event) {
        FacesContext.getCurrentInstance().addMessage(
                event.getComponent().getClientId(FacesContext.getCurrentInstance()),
                new FacesMessage(FacesMessage.SEVERITY_INFO, "Changes Stored Successfully",
                        "Changes Stored Successfully"));
    }

	/**
	 * @return the input
	 */
	public String getInput() {
		return input;
	}

	/**
	 * @param input the input to set
	 */
	public void setInput(String input) {
		if (input != null && input.equals(INPUT_TEXT)) {
			status = STATUS_TEXT;
		}
		this.input = input;
	}

	/**
	 * @return the status
	 */
	public String getStatus() {
		return status;
	}

	/**
	 * @param status the status to set
	 */
	public void setStatus(String status) {
		this.status = status;
	}
}
