1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package jdbcadmin.web.actions;
21
22 import java.util.List;
23
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26
27 import jdbcadmin.core.data.Line;
28 import jdbcadmin.core.data.Table;
29 import jdbcadmin.web.ContexteManager;
30 import jdbcadmin.web.util.HttpWrapper;
31
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
34 import org.apache.struts.action.ActionError;
35 import org.apache.struts.action.ActionErrors;
36 import org.apache.struts.action.ActionForm;
37 import org.apache.struts.action.ActionForward;
38 import org.apache.struts.action.ActionMapping;
39
40 /***
41 * @struts.action name="actionForm" path="/delete"
42 * @struts.action-forward name="main" path="/select.jsp"
43 * @struts.action-forward name="failure" path="/delete.jsp"
44 * @author Thomas Recloux (trecloux@norsys.fr)
45 */
46 public class DeleteAction extends IndexedAction {
47
48 /*** Logger */
49 private static Log logger = LogFactory.getLog(DeleteAction.class);
50
51 /***
52 * Constructor
53 */
54 public DeleteAction() {
55 super();
56 }
57
58 /***
59 * {@inheritDoc}
60 */
61 public ActionForward indexedExec(
62 ActionMapping mapping,
63 ActionForm form,
64 HttpServletRequest request,
65 HttpServletResponse response)
66 throws Exception {
67
68 ActionErrors errors = new ActionErrors();
69 ActionForward forward = new ActionForward();
70
71 String strForward = "main";
72
73
74 try {
75 Table tab = ContexteManager.getCurrentTable(request);
76 Line line = new Line(tab);
77 HttpWrapper.wrapLine(request, line);
78
79 request.setAttribute("line", line);
80
81 ContexteManager.getManager(request).delete(line);
82 request.setAttribute("messageInfo", getResources(request).getMessage("message.delete.ok"));
83
84 List lines = ContexteManager.getManager(request).select(tab,
85 ContexteManager.getIdxDonnees(request),
86 Constants.NB_LINES_PER_PAGE);
87
88 request.setAttribute("lines", lines);
89
90 } catch (Exception e) {
91 if (logger.isErrorEnabled()) {
92 logger.error("Unexpected error in the delete action", e);
93 }
94 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.generic", e.getMessage()));
95 strForward = "error";
96 }
97
98
99
100
101 if (!errors.isEmpty()) {
102 saveErrors(request, errors);
103 }
104
105
106 forward = mapping.findForward(strForward);
107
108
109 return (forward);
110
111 }
112 }