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.web.ContexteManager;
28 import jdbcadmin.web.forms.SelectTableForm;
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 * Select a table
40 * @struts.action
41 * name="selectTableForm"
42 * path="/selectTable"
43 * @struts.action-forward
44 * name="main"
45 * path="/select.jsp"
46 * @author Thomas Recloux (trecloux@norsys.fr)
47 */
48 public class SelectTableAction extends IndexedAction {
49
50 /*** Logger */
51 private static Log logger = LogFactory.getLog(SelectTableAction.class);
52
53 /***
54 * Constructor
55 */
56 public SelectTableAction() {
57 super();
58 }
59
60 /*** {@inheritDoc} */
61 public ActionForward indexedExec(
62 ActionMapping mapping,
63 ActionForm form,
64 HttpServletRequest request,
65 HttpServletResponse response)
66 throws Exception {
67
68 if (logger.isDebugEnabled()) {
69 logger.debug("BEGIN - SelectTableAction");
70 }
71 ActionErrors errors = new ActionErrors();
72 ActionForward forward = new ActionForward();
73 String fwdName = "main";
74
75 SelectTableForm selectTableForm = (SelectTableForm) form;
76
77 try {
78
79 ContexteManager.setCurrentTable(request, selectTableForm.getTable());
80 if (logger.isDebugEnabled()) {
81 logger.debug("Table : " + selectTableForm.getTable());
82 }
83
84 List lignes = ContexteManager.getLignes(request, 0, Constants.NB_LINES_PER_PAGE);
85 if (logger.isDebugEnabled()) {
86 logger.debug("Nb lines : " + lignes.size());
87 }
88 ContexteManager.setIdxDonnees(request, 0);
89
90 request.setAttribute("lines", lignes);
91
92 } catch (Exception e) {
93 if (logger.isErrorEnabled()) {
94 logger.error("unexpected error selecting the table", e);
95 }
96 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.generic", e.getMessage()));
97 fwdName = "error";
98 }
99
100
101
102
103 if (!errors.isEmpty()) {
104 saveErrors(request, errors);
105 }
106
107 forward = mapping.findForward(fwdName);
108
109
110 if (logger.isDebugEnabled()) {
111 logger.debug("END - SelectTableAction");
112 }
113
114 return (forward);
115
116 }
117 }