package com.jspdev.ch17;

import org.apache.struts.action.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
public final class AddEmployeeToDeptAction extends Action {

    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
        throws Exception {
        EmployeeBean service = new EmployeeBean();
        DynaActionForm f=(DynaActionForm)form;
        String employId=(String)f.get("employId");
        String deptId=(String)f.get("deptId");
		//String employId=request.getParameter("employId");
		//String deptId=request.getParameter("deptId");
        
        try {
             service.resetEmploy(employId,deptId);
              request.setAttribute("deptId",deptId);
            return (mapping.findForward("success"));
        }
        catch( Exception de ) {
            ActionErrors errors = new ActionErrors();
            ActionError error = new ActionError("error.employee.databaseException");
            errors.add( ActionErrors.GLOBAL_ERROR, error );
            saveErrors( request, errors );
            return (mapping.findForward("error"));
        }
    }
}