View Javadoc

1   /* ==============================================================================
2    *   JDBCAdmin, data management software.
3    *   Copyright (C) 2005  Norsys S.A
4    *
5    *   This library is free software; you can redistribute it and/or
6    *   modify it under the terms of the GNU Lesser General Public
7    *   License as published by the Free Software Foundation; either
8    *   version 2.1 of the License, or (at your option) any later version.
9    *
10   *   This library is distributed in the hope that it will be useful,
11   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   *   Lesser General Public License for more details.
14   *
15   *   You should have received a copy of the GNU Lesser General Public
16   *   License along with this library; if not, write to the Free Software
17   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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          // return value
75          SelectTableForm selectTableForm = (SelectTableForm) form;
76  
77          try {
78              // Store the table
79              ContexteManager.setCurrentTable(request, selectTableForm.getTable());
80              if (logger.isDebugEnabled()) {
81                  logger.debug("Table : " + selectTableForm.getTable());
82              }
83              // Loading the first datas
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         // If a message is required, save the specified key(s)
101         // into the request for use by the <struts:errors> tag.
102 
103         if (!errors.isEmpty()) {
104             saveErrors(request, errors);
105         }
106         // Write logic determining how the user should be forwarded.
107         forward = mapping.findForward(fwdName);
108 
109 
110         if (logger.isDebugEnabled()) {
111             logger.debug("END - SelectTableAction");
112         }
113         // Finish with
114         return (forward);
115 
116     }
117 }