/** * The doPost method of the servlet. <br> * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); String path = "/WEB-INF/jsp/client/assets/retirement/index.jsp"; String action = request.getParameter("action"); boolean processList = false; if (action == null) { action = "list"; } try { PersonBean person = (PersonBean) session.getAttribute("person"); if (person == null) { throw new NullPointerException(); } if (action.equalsIgnoreCase("add")) { RetirementBean bean = new RetirementBean(); bean.initialize(); request.setAttribute("retire", bean); request.setAttribute("btn", "Add"); request.setAttribute("ownerOptions", InputMaps.ownershipTypes); request.setAttribute("titleOptions", InputMaps.titleTypes); request.setAttribute("notesPayOptions", InputMaps.notePayTypes); path = "/WEB-INF/jsp/client/assets/retirement/form.jsp"; } if (action.equalsIgnoreCase("edit")) { RetirementBean bean = new RetirementBean(); int id = Utils.getIntegerParameter(request, "id", -1); if (id > 0) { bean.setId(id); bean.initialize(); request.setAttribute("retire", bean); request.setAttribute("btn", "Edit"); request.setAttribute("ownerOptions", InputMaps.ownershipTypes); request.setAttribute("titleOptions", InputMaps.titleTypes); request.setAttribute("retirementOptions", InputMaps.notePayTypes); path = "/WEB-INF/jsp/client/assets/retirement/form.jsp"; } else { processList = true; } } if (action.equalsIgnoreCase("insert")) { RetirementBean bean = new RetirementBean(); processForm(bean, request); bean.insert(); processList = true; } if (action.equalsIgnoreCase("update")) { RetirementBean bean = new RetirementBean(); processForm(bean, request); bean.update(); processList = true; } if (action.equalsIgnoreCase("delete")) { RetirementBean bean = new RetirementBean(); int id = Utils.getIntegerParameter(request, "id", -1); if (id > 0) { bean.setId(id); bean.delete(); } processList = true; } if (action.equalsIgnoreCase("view")) { RetirementBean bean = new RetirementBean(); int id = Utils.getIntegerParameter(request, "id", -1); if (id > 0) { bean.setId(id); bean.initialize(); request.setAttribute("retire", bean); path = "/WEB-INF/jsp/client/assets/retirement/view.jsp"; } } if (action.equalsIgnoreCase("cancel")) { processList = true; } if (action.equalsIgnoreCase("list") || processList) { RetirementBean retirement = new RetirementBean(); ArrayList<RetirementBean> cList = retirement.getBeans(RetirementBean.OWNER_ID + "='" + person.getId() + "'"); request.setAttribute("cList", cList); path = "/WEB-INF/jsp/client/assets/retirement/index.jsp"; } } catch (Exception e) { System.err.println("Person Bean not found"); path = "/admin/selectClient"; } RequestDispatcher dispatch = request.getRequestDispatcher(path); dispatch.forward(request, response); }