package com.javahonk.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.validator.annotations.EmailValidator;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;

@Results({
		@Result(name = "error", location = "/index.jsp"),
		@Result(name = "input", location = "/index.jsp")})
public class FormValidationAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private String firstName;
	private String lastName;
	private String email;

	@Override
	@Action(value = "/formValidationAction")
	public String execute() throws Exception {
		return ActionSupport.INPUT;
	}

	public String getFirstName() {
		return firstName;
	}

	@RequiredStringValidator(message = "First name is required.")
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	@RequiredStringValidator(message = "Last name is required.")
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getEmail() {
		return email;
	}

	@RequiredStringValidator(message = "Email id is required.")
	@EmailValidator(message = "Please enter valid email.")
	public void setEmail(String email) {
		this.email = email;
	}	
	
}
