View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.tuigwaa.controller;
17  
18  import javax.servlet.http.HttpServletRequest;
19  import javax.servlet.http.HttpServletResponse;
20  
21  import org.apache.struts.action.ActionForm;
22  import org.apache.struts.action.ActionForward;
23  import org.apache.struts.action.ActionMapping;
24  import org.apache.struts.actions.MappingDispatchAction;
25  import org.seasar.tuigwaa.database.function.UpdateExeFunction;
26  import org.seasar.tuigwaa.model.DAOService;
27  import org.seasar.tuigwaa.model.core.TgwEntity;
28  import org.seasar.tuigwaa.system.Constants;
29  import org.seasar.tuigwaa.util.TgwUtils;
30  
31  import com.isenshi.util.extlib.StrutsUtil;
32  
33  public class CustomFormAction extends MappingDispatchAction {
34  
35  	public ControllerService controllerService;
36  
37  	public DAOService daoService;
38  
39  	public CustomFormAction(ControllerService strutsService,
40  			DAOService daoService) {
41  		this.daoService = daoService;
42  		this.controllerService = strutsService;
43  	}
44  
45  	public ActionForward create(ActionMapping mapping, ActionForm form,
46  			HttpServletRequest request, HttpServletResponse response)
47  			throws Exception {
48  		TgwEntity entity = TgwUtils.getEntity(request, getServlet());
49  		CustomFormForm customFormForm = new CustomFormForm(entity);
50  		request.getSession().setAttribute(Constants.SATTR_FORM_CUSTOMFORM,
51  				customFormForm);
52  		return mapping.findForward("success");
53  	}
54  
55  	public ActionForward edit(ActionMapping mapping, ActionForm form,
56  			HttpServletRequest request, HttpServletResponse response)
57  			throws Exception {
58  		TgwEntity entity = TgwUtils.getEntity(request, getServlet());
59  		String filterName = StrutsUtil.getURLDecodedParameter(request,
60  				Constants.PARAM_ENTITY_FILTER);
61  
62  		UpdateExeFunction function = (UpdateExeFunction) daoService
63  				.getCustomFormFunctionMap(entity).get(filterName);
64  
65  		CustomFormForm customFormForm = new CustomFormForm(entity, function);
66  		request.getSession().setAttribute(Constants.SATTR_FORM_CUSTOMFORM,
67  				customFormForm);
68  		return mapping.findForward("success");
69  	}
70  
71  	public ActionForward save(ActionMapping mapping, ActionForm form,
72  			HttpServletRequest request, HttpServletResponse response)
73  			throws Exception {
74  		CustomFormForm cformform = (CustomFormForm) form;
75  		// CustomForm cform = cformform.getCustomForm();
76  
77  		UpdateExeFunction updateExe = cformform.getUpdateExeFunction();
78  		TgwEntity entity = cformform.getEntity();
79  
80  		daoService.registerDaoMethod(entity, updateExe);
81  		controllerService.addCustomFormConfig(entity, updateExe);
82  		daoService.saveFunction(entity);
83  
84  		return TgwUtils.dialoggCloseAndListRecordForward(mapping, request,
85  				entity.getName(), null);
86  
87  	}
88  
89  	public ActionForward delete(ActionMapping mapping, ActionForm form,
90  			HttpServletRequest request, HttpServletResponse response)
91  			throws Exception {
92  		TgwEntity entity = TgwUtils.getEntity(request, getServlet());
93  		String filterName = StrutsUtil.getURLDecodedParameter(request,
94  				Constants.PARAM_ENTITY_DELETEFILTER);
95  
96  		daoService.deregisterDaoMethod(entity, filterName);
97  		controllerService.removeCustomFormConfig(entity, filterName);
98  		daoService.saveFunction(entity);
99  
100 		return mapping.findForward("listRecord");
101 	}
102 }