private static final String EDIT_ACTION = "edit";
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
AcademyService academyService = null;
try {
academyService = (AcademyService) BusinessUtil
.findBusiness("AcademyService");
} catch (Exception e) {
e.printStackTrace();
}
String targetPage = null;
String method = getInitParameter("method");
targetPage = getInitParameter("page");
if (TABLE_ACTION.equals(method)) {
} else if (PRE_ADD_ACTION.equals(method)) {
} else if (ADD_ACTION.equals(method)) {
String academyName = req.getParameter("academyName");
String academyAddress = req.getParameter("academyAddress");
String academyLogin = req.getParameter("academyLogin");
String academyPassword = req.getParameter("academyPassword");
Academy academy = new Academy();
academy.setName(academyName);
academy.setAddress(academyAddress);
academy.setRegistrationDate(new Date());
academy.setUserLogin(academyLogin);
academy.setUserPassword(academyPassword);
try {
academyService.save(academy);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
req.setAttribute("refreshTableFunction", "refreshAcademyTable");
} else if (PRE_EDIT_ACTION.equals(method)) {
Integer id = Integer.valueOf(req.getParameter("id"));
try {
Academy academy = academyService.load(id);
req.setAttribute("academyId", String.valueOf(id));
req.setAttribute("academyName", academy.getName());
req.setAttribute("academyAddress", academy.getAddress());
req.setAttribute("academyLogin", academy.getUserLogin());
req.setAttribute("academyPassword", academy.getUserPassword());
} catch (Exception e) {
e.printStackTrace();
}
req.setAttribute("isEdit", Boolean.TRUE);
} else if (EDIT_ACTION.equals(method)) {
String academyId = req.getParameter("academyId");
String academyName = req.getParameter("academyName");
String academyAddress = req.getParameter("academyAddress");
String academyLogin = req.getParameter("academyLogin");
String academyPassword = req.getParameter("academyPassword");
Academy academy = new Academy();
academy.setIdAcademy(Integer.valueOf(academyId));
academy.setName(academyName);
academy.setAddress(academyAddress);
academy.setRegistrationDate(new Date());
academy.setUserLogin(academyLogin);
academy.setUserPassword(academyPassword);
try {
academyService.update(academy);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
req.setAttribute("refreshTableFunction", "refreshAcademyTable");