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.Table;
28 import jdbcadmin.core.exceptions.DataNotFoundException;
29 import jdbcadmin.web.ContexteManager;
30 import jdbcadmin.web.forms.OtherDataForm;
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 * Retrieves more data
42 * @struts.action
43 * name="otherDataForm"
44 * path="/otherData"
45 * @struts.action-forward
46 * name="main"
47 * path="/select.jsp"
48 * @author Thomas Recloux (trecloux@norsys.fr)
49 */
50 public class OtherDataAction extends IndexedAction {
51
52 /*** Logger */
53 private static Log logger = LogFactory.getLog(OtherDataAction.class);
54
55 /*** {@inheritDoc} */
56 public ActionForward indexedExec(
57 ActionMapping mapping,
58 ActionForm form,
59 HttpServletRequest request,
60 HttpServletResponse response)
61 throws Exception {
62
63
64 if (logger.isDebugEnabled()) {
65 logger.debug("BEGIN OtherDataAction");
66 }
67 ActionErrors errors = new ActionErrors();
68 ActionForward forward = new ActionForward();
69 String strFwd = "main";
70
71 OtherDataForm autresDonneesForm = (OtherDataForm) form;
72 int idxOriginal = 0;
73
74 try {
75 idxOriginal = ContexteManager.getIdxDonnees(request);
76 int idx = idxOriginal;
77 if (OtherDataForm.DIR_AFTER.equals(autresDonneesForm.getDirection())) {
78 idx = idx + Constants.NB_LINES_PER_PAGE;
79 } else {
80 idx = idx - Constants.NB_LINES_PER_PAGE;
81 if (idx < 0) {
82 idx = 0;
83 }
84 }
85 if (logger.isDebugEnabled()) {
86 logger.debug("Start index: " + idx);
87 }
88 Table tab = ContexteManager.getCurrentTable(request);
89 if (logger.isDebugEnabled()) {
90 logger.debug("Table : " + tab.getCompleteName());
91 }
92 List lignes = ContexteManager.getManager(request).select(tab
93 , idx, Constants.NB_LINES_PER_PAGE);
94 if (logger.isDebugEnabled()) {
95 logger.debug(lignes.size() + " lignes retrieved");
96 }
97 ContexteManager.setIdxDonnees(request, idx);
98 request.setAttribute("lines", lignes);
99 } catch (DataNotFoundException dnfe) {
100
101 try {
102 Table tab = ContexteManager.getCurrentTable(request);
103 List lignes = ContexteManager.getManager(request).select(tab
104 , idxOriginal, Constants.NB_LINES_PER_PAGE);
105 ContexteManager.setIdxDonnees(request, idxOriginal);
106 request.setAttribute("lines", lignes);
107 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.endtable"));
108 strFwd = "main";
109 } catch (Exception e) {
110 if (logger.isErrorEnabled()) {
111 logger.error("Erreur non prévue lors l'action de recuperation d'autres données", e);
112 }
113 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("erreur.generique", e));
114 strFwd = "erreur";
115 }
116 } catch (Exception e) {
117 if (logger.isErrorEnabled()) {
118 logger.error("Unexexted error retrieving other data", e);
119 }
120 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.generic", e));
121 strFwd = "error";
122 }
123
124
125
126
127 if (!errors.isEmpty()) {
128 saveErrors(request, errors);
129 }
130
131 forward = mapping.findForward(strFwd);
132
133 if (logger.isDebugEnabled()) {
134 logger.debug("END OtherDataAction");
135 }
136
137 return (forward);
138
139 }
140 }