/**
* Copyright (C) 2006 - present dabuTech Corporation
* All Rights Reserved.
*
* This file is part of Easier Java Websites.
*
* EJW is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the accompanying license
* for more details.
*
* You should have received a copy of the license along with EJW; if not,
* go to http://www.EasierJava.com and download the latest version.
*/
package webapp;
import ejp.DatabaseManager;
import java.util.ArrayList;
import ejw.RequestHandler;
import java.util.List;
public class Customers extends RequestHandler
{
// default request loads customer database into list for the view
public String request() throws Exception
{
DatabaseManager dbm = AppUtils.getDatabaseManager(getServerInterface());
List<Customer> customers = (ArrayList<Customer>)dbm.loadObjects(new ArrayList<Customer>(), Customer.class);
getServerInterface().addViewObject("customersList", customers);
return getServerInterface().getUrl("view");
}
// validate with webapp.xml definitions
public String validateSaveCustomer() throws Exception
{
if (!getServerInterface().validateParameters())
{
getServerInterface().addViewObject("customerForm", getServerInterface().fillObject(new Customer()));
return getServerInterface().getUrl("customers");
}
return SUCCESS;
}
// if validation succeeds, save data and return to customer view
public String saveCustomer() throws Exception
{
Customer customer = getServerInterface().fillObject(new Customer());
AppUtils.getDatabaseManager(getServerInterface()).saveObject(customer);
return getServerInterface().getUrl("customers");
}
public static class Customer
{
private String firstName, lastName, companyName, phone, email;
public String getFirstName() { return firstName; }
public void setFirstName(String firstName) { this.firstName = firstName; }
public String getLastName() { return lastName; }
public void setLastName(String lastName) { this.lastName = lastName; }
public String getCompanyName() { return companyName; }
public void setCompanyName(String companyName) { this.companyName = companyName; }
public String getPhone() { return phone; }
public void setPhone(String phone) { this.phone = phone; }
public String getEmail() { return email; }
public void setEmail(String email) { this.email = email; }
}
}