KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dlog4j > action > DlogParamAction


1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */

16 package dlog4j.action;
17
18 import java.sql.SQLException JavaDoc;
19
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import javax.servlet.http.HttpServletResponse JavaDoc;
22
23 import net.sf.hibernate.HibernateException;
24 import net.sf.hibernate.Session;
25
26 import org.apache.struts.action.ActionError;
27 import org.apache.struts.action.ActionErrors;
28 import org.apache.struts.action.ActionForm;
29 import org.apache.struts.action.ActionForward;
30 import org.apache.struts.action.ActionMapping;
31
32 import dlog4j.SiteManager;
33 import dlog4j.formbean.ParamForm;
34 import dlog4j.formbean.SiteForm;
35
36 /**
37  * 参数设置的Action
38  *
39  * @author Liudong
40  */

41 public class DlogParamAction extends AdminActionBase {
42
43     /**
44      * 修改参数值
45      * @param mapping
46      * @param form
47      * @param request
48      * @param response
49      * @return
50      * @throws Exception
51      */

52     public ActionForward doUpdateParam(ActionMapping mapping,
53             ActionForm form, HttpServletRequest JavaDoc request,
54             HttpServletResponse JavaDoc response) throws Exception JavaDoc
55     {
56         ActionErrors errors = new ActionErrors();
57         ParamForm param = (ParamForm)form;
58         Session ssn = null;
59         try {
60             ssn = getSession();
61             SiteForm site = SiteManager.getCurrentSite(request);
62             ParamForm pa = (ParamForm)ssn.load(ParamForm.class,new Integer JavaDoc(param.getId()));
63             if(pa!=null) {
64                 if(!pa.getValue().equals(param.getValue())) {
65                     pa.setType(param.getType());
66                     pa.setValue(param.getValue());
67                     ssn.update(pa);
68                 }
69             }
70         } catch(SQLException JavaDoc e) {
71             errors.add("param",new ActionError("database_exception"));
72         } catch(HibernateException e) {
73             errors.add("param",new ActionError("hibernate_exception"));
74         } finally {
75             commitSession(ssn, true);
76         }
77         // Report any errors we have discovered back to the original form
78
if (!errors.isEmpty())
79             saveErrors(request, errors);
80         ActionForward forward = mapping.getInputForward();
81         if(errors.isEmpty())
82             forward.setRedirect(true);
83         return forward;
84     }
85
86 }
87
Popular Tags