package com.javaskool;

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

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;


public class PassengerAction extends ActionSupport implements ModelDriven<Passenger>{

	private static final long serialVersionUID = 1L;
	Passenger  passenger  = new Passenger();
	List<Passenger> passengers = new ArrayList<Passenger>();
   
   PassengerDAO dao = new PassengerDAO();
   
   @Override
   public Passenger getModel() {
      return passenger;
   }

   public String execute()
   {
	   try{
      dao.addPassenger(passenger);
	   }
	   catch(Exception e){}
      return "success";
   }

   public String listPassengers()
   {
	   passengers = dao.getPassengers();
      return "success";
   }

public Passenger getPassenger() {
	return passenger;
}

public void setPassenger(Passenger passenger) {
	this.passenger = passenger;
}

public List<Passenger> getPassengers() {
	return passengers;
}

public void setPassengers(List<Passenger> passengers) {
	this.passengers = passengers;
}

 	
}


/*You will notice that we are implementing the ModelDriven interface. 
 * This is used when your action class is dealing with a concrete model class 
 * (such as Passenger) as opposed to individual properties (such as firstName, lastName). 
 * The ModelAware interface requires you to implement a method to return the model. 
 * In our case we are returning the "passenger" object.*/

