package com.javahonk.action;

import java.util.ArrayList;
import java.util.List;

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

import com.opensymphony.xwork2.ActionSupport;

@ParentPackage("json-default")
public class StrutsPaginationAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private int iTotalRecords;
	private int iTotalDisplayRecords;
	private String sEcho;
	private String sColumns;
	private List<Person> aaData;
	private List<Person> personsList = new ArrayList<Person>();

	public StrutsPaginationAction() {

		for (int i = 0; i < 1; i++) {
			Person person2 = new Person();
			person2.setName("John Landy");
			person2.setPosition("System Architect");
			person2.setSalary("$320,800");
			person2.setOffice("NY");
			person2.setPhone("999999999");
			person2.setStart_date("05/05/2010");
			personsList.add(person2);

			person2 = new Person();
			person2.setName("Igor Vornovitsky");
			person2.setPosition("Solution Architect");
			person2.setSalary("$340,800");
			person2.setOffice("NY");
			person2.setPhone("987897899");
			person2.setStart_date("05/05/2010");
			personsList.add(person2);

			person2 = new Person();
			person2.setName("Java Honk");
			person2.setPosition("Architect");
			person2.setSalary("$380,800");
			person2.setOffice("NY");
			person2.setPhone("1234567890");
			person2.setStart_date("05/05/2010");
			personsList.add(person2);

			person2 = new Person();
			person2.setName("Ramesh Arrepu");
			person2.setPosition("Sr. Architect");
			person2.setSalary("$310,800");
			person2.setOffice("NY");
			person2.setPhone("4654321234");
			person2.setStart_date("05/05/2010");
			personsList.add(person2);

			person2 = new Person();
			person2.setName("Bob Sidebottom");
			person2.setPosition("Architect");
			person2.setSalary("$300,800");
			person2.setOffice("NJ");
			person2.setPhone("9876543212");
			person2.setStart_date("05/05/2010");
			personsList.add(person2);

		}

		for (int i = 0; i < 50; i++) {
			Person person2 = new Person();
			person2.setName("Zuke Torres");
			person2.setPosition("System Architect");
			person2.setSalary("$320,800");
			person2.setOffice("NY");
			person2.setPhone("999999999");
			person2.setStart_date("05/05/2010");
			personsList.add(person2);
		}

		setiTotalDisplayRecords(personsList.size());
		setiTotalRecords(personsList.size());
		setAaData(personsList);

	}

	@Override
	@Action(value = "/strutsPaginationAction", results = { @Result(name = "success", type = "json") })
	public String execute() throws Exception {
		return ActionSupport.SUCCESS;
	}

	public List<Person> getPersonsList() {
		return personsList;
	}

	public void setPersonsList(List<Person> personsList) {
		this.personsList = personsList;
	}

	public int getiTotalRecords() {
		return iTotalRecords;
	}

	public void setiTotalRecords(int iTotalRecords) {
		this.iTotalRecords = iTotalRecords;
	}

	public int getiTotalDisplayRecords() {
		return iTotalDisplayRecords;
	}

	public void setiTotalDisplayRecords(int iTotalDisplayRecords) {
		this.iTotalDisplayRecords = iTotalDisplayRecords;
	}

	public String getsEcho() {
		return sEcho;
	}

	public void setsEcho(String sEcho) {
		this.sEcho = sEcho;
	}

	public String getsColumns() {
		return sColumns;
	}

	public void setsColumns(String sColumns) {
		this.sColumns = sColumns;
	}

	public List<Person> getAaData() {
		return aaData;
	}

	public void setAaData(List<Person> aaData) {
		this.aaData = personsList;
	}

}
