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 java.util.Collection;
19  import java.util.Iterator;
20  
21  import javax.servlet.http.HttpServletRequest;
22  import javax.servlet.http.HttpServletResponse;
23  
24  import org.apache.struts.action.ActionForm;
25  import org.apache.struts.action.ActionForward;
26  import org.apache.struts.action.ActionMapping;
27  import org.apache.struts.actions.MappingDispatchAction;
28  import org.seasar.tuigwaa.database.function.SearchExeFunction;
29  import org.seasar.tuigwaa.database.function.UpdateExeFunction;
30  import org.seasar.tuigwaa.database.function.criteria.CriteriaListFunction;
31  import org.seasar.tuigwaa.model.DAOService;
32  import org.seasar.tuigwaa.model.ModelService;
33  import org.seasar.tuigwaa.model.common.EntityInfo;
34  import org.seasar.tuigwaa.model.core.TgwEntity;
35  import org.seasar.tuigwaa.system.Constants;
36  import org.seasar.tuigwaa.util.TgwUtils;
37  
38  import com.isenshi.util.extlib.StrutsUtil;
39  
40  public class SearchFormAction extends MappingDispatchAction {
41  
42  	public DAOService daoService;
43  
44  	public ControllerService strutsService;
45  	
46  	public ModelService modelservice;
47  
48  	public SearchFormAction(DAOService daoService,
49  			ControllerService strutsService,ModelService modelService) {
50  		this.daoService = daoService;
51  		this.strutsService = strutsService;
52  		this.modelservice = modelService;
53  	}
54  
55  	public ActionForward create(ActionMapping mapping, ActionForm form,
56  			HttpServletRequest request, HttpServletResponse response)
57  			throws Exception {
58  		TgwEntity entity = TgwUtils.getEntity(request, getServlet());
59  		SearchFormForm searchFormForm = new SearchFormForm(entity);
60  		request.getSession().setAttribute(Constants.SATTR_FORM_SEARCHFORM,
61  				searchFormForm);
62  		return mapping.findForward("success");
63  	}
64  
65  	public ActionForward save(ActionMapping mapping, ActionForm form,
66  			HttpServletRequest request, HttpServletResponse response)
67  			throws Exception {
68  		SearchFormForm searchFormForm = (SearchFormForm) form;
69  		SearchExeFunction exeFunction = searchFormForm.getSearchExeFunction();
70  		TgwEntity entity = searchFormForm.getEntity();
71  		daoService.registerDaoMethod(entity, exeFunction);
72  		strutsService.addSearchConfig(entity, exeFunction);
73  		daoService.saveFunction(entity);
74  		return TgwUtils.dialoggCloseAndListRecordForward(mapping, request,
75  				entity.getName(), null);
76  	}
77  	public ActionForward edit(ActionMapping mapping, ActionForm form,
78  			HttpServletRequest request, HttpServletResponse response)
79  			throws Exception {
80  		TgwEntity entity = TgwUtils.getEntity(request, getServlet());
81  		String filterName = StrutsUtil.getURLDecodedParameter(request,
82  				Constants.PARAM_ENTITY_FILTER);
83  
84  		EntityInfo info = modelservice.createEntityInfo(entity.getDomainName(),
85  				entity.getName());
86  		
87  		Collection collection = info.getSearchFormList();
88  		
89  		System.out.println("collection.size:"+collection.size());
90  
91  		SearchExeFunction function = null;
92  		
93  		Iterator itr = collection.iterator();
94  		while (itr.hasNext()) {
95  			SearchExeFunction func = (SearchExeFunction) itr.next();
96  			if (filterName != null && filterName.equals(func.getName())) {
97  				function = func;
98  			}
99  		}
100 		
101 		SearchFormForm searchFormForm = new SearchFormForm(entity,function);
102 		request.getSession().setAttribute(Constants.SATTR_FORM_SEARCHFORM,
103 				searchFormForm);
104 		
105 		return mapping.findForward("success");
106 	}
107 
108 	public ActionForward delete(ActionMapping mapping, ActionForm form,
109 			HttpServletRequest request, HttpServletResponse response)
110 			throws Exception {
111 		TgwEntity entity = TgwUtils.getEntity(request, getServlet());
112 		String filterName = StrutsUtil.getURLDecodedParameter(request,
113 				Constants.PARAM_ENTITY_DELETEFILTER);
114 
115 		daoService.deregisterDaoMethod(entity, filterName);
116 		strutsService.removeSearchConfig(entity, filterName);
117 		daoService.saveFunction(entity);
118 
119 		return mapping.findForward("listRecord");
120 	}
121 }