rendered paste body/*
* CustomerRegister.java
*
* Created on 22 November 2006, 21:36
*/
package org.cbcc.controller;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMessages;
import org.cbcc.beans.CustomerRegisterBean;
import org.cbcc.classes.Customer;
/**
*
* @author Owner
* @version
*/
public class CustomerRegister extends Action {
/* forward name="success" path="" */
private final static String SUCCESS = "success";
/**
* This is the action called from the Struts framework.
* @param mapping The ActionMapping used to select this instance.
* @param form The optional ActionForm bean for this request.
* @param request The HTTP Request we are processing.
* @param response The HTTP Response we are processing.
* @throws java.lang.Exception
* @return
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
CustomerRegisterBean customerRegistrationForm = (CustomerRegisterBean) form;
if(customerRegistrationForm.getSumbit() != null) {
// the form has been submited
ActionMessages errors = (ActionMessages) form.validate(mapping, request);
if(errors.isEmpty()) {
Customer customer = new Customer();
//Cant find methods form.getFirstName() and form.getSecondName
//the bean has these methods
customer.setFirstName(form);
customer.setSecondName(form.getSecondname());
Vector customerList = (Vector) this.getServlet().getServletContext().getAttribute("customers");
customerList.add(customer);
return mapping.findForward("registerSuccess");
} else {
saveErrors(request, errors);
return mapping.findForward("registerForm");
}
} else {
return mapping.findForward("registerForm");
}
}
}