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 javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24
25 import jdbcadmin.core.data.Line;
26 import jdbcadmin.core.data.Table;
27 import jdbcadmin.web.ContexteManager;
28 import jdbcadmin.web.util.HttpWrapper;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.apache.struts.action.ActionError;
33 import org.apache.struts.action.ActionErrors;
34 import org.apache.struts.action.ActionForm;
35 import org.apache.struts.action.ActionForward;
36 import org.apache.struts.action.ActionMapping;
37
38 /***
39 * Actions on a line (update, delete)
40 * @author Thomas Recloux (trecloux@norsys.fr)
41 * @struts.action
42 * name="actionForm"
43 * path="/lineAction"
44 * @struts.action-forward
45 * name="update"
46 * path="/update.jsp"
47 * @struts.action-forward
48 * name="confirmDelete"
49 * path="/delete.jsp"
50 */
51 public class LineAction extends IndexedAction {
52
53 /*** Logger */
54 private static Log logger = LogFactory.getLog(LineAction.class);
55
56 /*** {@inheritDoc} */
57 public ActionForward indexedExec(
58 ActionMapping mapping,
59 ActionForm form,
60 HttpServletRequest request,
61 HttpServletResponse response)
62 throws Exception {
63
64 ActionErrors errors = new ActionErrors();
65 ActionForward forward = new ActionForward();
66 jdbcadmin.web.forms.ActionForm actionForm = (jdbcadmin.web.forms.ActionForm) form;
67 String strForward = "update";
68
69
70 try {
71 Table tab = ContexteManager.getCurrentTable(request);
72 Line ligne = new Line(tab);
73 HttpWrapper.wrapLine(request, ligne);
74
75 request.setAttribute("line", ligne);
76
77 if (actionForm.getTypeAction().equals("update")) {
78 strForward = "update";
79 } else if (actionForm.getTypeAction().equals("delete")) {
80 strForward = "confirmDelete";
81 }
82
83 } catch (Exception e) {
84 if (logger.isErrorEnabled()) {
85 logger.error("Unexpeted error during the action", e);
86 }
87 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.generic", e.getMessage()));
88 strForward = "error";
89 }
90
91
92
93
94 if (!errors.isEmpty()) {
95 saveErrors(request, errors);
96 }
97
98 forward = mapping.findForward(strForward);
99
100
101 return (forward);
102 }
103 }