1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
| public class ElectorController extends HttpServlet {
private static final long serialVersionUID = 1L;
RequestDispatcher dispatcher = null;
ElectorDAO electorDAO = null;
public ElectorController() {
electorDAO = new ElectorDAOImpl();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String action = request.getParameter("action");
if(action == null) {
action = "LIST";
}
switch(action) {
case "LIST":
listElector(request, response);
break;
case "NEW":
newElector(request, response);
break;
case "EDIT":
getSingleElector(request, response);
break;
case "SEDIT":
getSingleElectorAdmin(request, response);
break;
case "add":
addElector(request, response);
break;
case "update":
updateElector(request, response);
break;
case "DELETE":
deleteElector(request, response);
break;
default:
listElector(request, response);
break;
}
}
private void deleteElector(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Elector e = new Elector();
e.setId(request.getParameter("id"));
if(electorDAO.delete(e)) {
request.setAttribute("NOTIFICATION", "Électeur supprimé avec succès!");
}
listElector(request, response);
}
private void newElector(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
dispatcher = request.getRequestDispatcher("/views/elector-add.jsp");
dispatcher.forward(request, response);
}
private void getSingleElector(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
String id = request.getParameter("id");
Elector theElector = electorDAO.get(id);
request.setAttribute("elector", theElector);
dispatcher = request.getRequestDispatcher("/views/elector-edit.jsp");
dispatcher.forward(request, response);
}
private void getSingleElectorAdmin(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
String id = request.getParameter("id");
Elector theElector = electorDAO.get(id);
request.setAttribute("elector", theElector);
dispatcher = request.getRequestDispatcher("/views/elector-Sedit.jsp");
dispatcher.forward(request, response);
}
private void listElector(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<Elector> theList = electorDAO.get();
request.setAttribute("list", theList);
dispatcher = request.getRequestDispatcher("/views/elector-list.jsp");
dispatcher.forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
private void addElector(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Elector e = new Elector();
e.setId(request.getParameter("id"));
e.setFirstname(request.getParameter("firstname"));
e.setLastname(request.getParameter("lastname"));
e.setBdate(request.getParameter("bdate"));
e.setZipcode(request.getParameter("zipcode"));
e.setAdress(request.getParameter("adress"));
e.setCadress(request.getParameter("cadress"));
e.setEtat(request.getParameter("etat"));
e.setPhone(request.getParameter("phone"));
e.setDinscrit(request.getParameter("dinscrit"));
e.setStatus(request.getParameter("status"));
e.setDmodification(request.getParameter("dmodification"));
e.setNote(request.getParameter("note"));
e.setVote_etat(request.getParameter("vote_etat"));
e.setVote_centre(request.getParameter("vote_centre"));
if(electorDAO.add(e)) {
request.setAttribute("NOTIFICATION", "Électeur enregistré avec succès!");
listElector(request, response);
}
}
private void updateElector(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Elector e = new Elector();
e.setId(request.getParameter("id"));
e.setFirstname(request.getParameter("firstname"));
e.setLastname(request.getParameter("lastname"));
e.setBdate(request.getParameter("bdate"));
e.setZipcode(request.getParameter("zipcode"));
e.setAdress(request.getParameter("adress"));
e.setCadress(request.getParameter("cadress"));
e.setEtat(request.getParameter("etat"));
e.setPhone(request.getParameter("phone"));
e.setDinscrit(request.getParameter("dinscrit"));
e.setStatus(request.getParameter("status"));
e.setDmodification(request.getParameter("dmodification"));
e.setNote(request.getParameter("note"));
e.setVote_etat(request.getParameter("vote_etat"));
e.setVote_centre(request.getParameter("vote_centre"));
if(electorDAO.update(e)) {
request.setAttribute("NOTIFICATION", "Électeur a été mis à jour avec succès!");
listElector(request, response);
}
}
} |
Partager