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.util.ajax;
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  
26  import com.isenshi.util.extlib.StrutsUtil;
27  
28  public abstract class AbstractRowSetAction extends MappingDispatchAction {
29  
30  	private ActionForward editForward_;
31  
32  	private ActionForward baseForward_;
33  	
34  	public abstract String getFormName();
35  
36  	public abstract String getEditPath();
37  
38  	public abstract String getBasePath();
39  	
40  	public abstract RowSetForm getNewRowSet(ActionMapping mapping,
41  			ActionForm form, HttpServletRequest request,
42  			HttpServletResponse response) throws Exception;
43  
44  	public abstract RowSetForm getRowSet(ActionMapping mapping,
45  			ActionForm form, HttpServletRequest request,
46  			HttpServletResponse response) throws Exception;
47  
48  	public abstract ActionForward doSave(ActionMapping mapping,
49  			ActionForm form, HttpServletRequest request,
50  			HttpServletResponse response) throws Exception;
51  
52  	public ActionForward createNewRowSet(ActionMapping mapping,
53  			ActionForm form, HttpServletRequest request,
54  			HttpServletResponse response) throws Exception {
55  
56  		RowSetForm rowSetForm = getNewRowSet(mapping, form, request, response);
57  		
58  		StrutsUtil.bindSessionForm(request, getFormName(), (ActionForm)rowSetForm);
59  		return getEditForward();
60  	}
61  
62  	public ActionForward editRowSet(ActionMapping mapping,
63  			ActionForm form, HttpServletRequest request,
64  			HttpServletResponse response) throws Exception {
65  
66  		RowSetForm rowSetForm = getRowSet(mapping, form, request, response);
67  		
68  		StrutsUtil.bindSessionForm(request, getFormName(), (ActionForm)rowSetForm);
69  		return getEditForward();
70  	}
71  	
72  	public ActionForward saveRowSet(ActionMapping mapping,
73  			ActionForm form, HttpServletRequest request,
74  			HttpServletResponse response) throws Exception {
75  
76  				
77  		ActionForward forward = doSave(mapping, form, request, response);
78  		StrutsUtil.clearSessionForm(request, mapping);
79  		
80  		if(forward != null){
81  			return forward;
82  		}else{
83  			return getBaseForward();
84  		}
85  	}
86  		
87  	public ActionForward getEditForward(){
88  		if(editForward_ == null){
89  			editForward_ = new ActionForward();
90  			editForward_.setPath(getEditPath());
91  		}
92  		return editForward_;
93  	}
94  
95  	public ActionForward getBaseForward(){
96  		if(baseForward_ == null){
97  			baseForward_ = new ActionForward();
98  			baseForward_.setPath(getBasePath());
99  		}
100 		return baseForward_;
101 	}
102 }