View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.web.controller;
17  
18  import org.kuali.rice.krad.uif.UifConstants;
19  import org.kuali.rice.krad.uif.field.AttributeQueryResult;
20  import org.kuali.rice.krad.util.GlobalVariables;
21  import org.kuali.rice.krad.web.form.UifFormBase;
22  import org.kuali.rice.krad.web.service.CollectionControllerService;
23  import org.kuali.rice.krad.web.service.ControllerService;
24  import org.kuali.rice.krad.web.service.FileControllerService;
25  import org.kuali.rice.krad.web.service.ModelAndViewService;
26  import org.kuali.rice.krad.web.service.NavigationControllerService;
27  import org.kuali.rice.krad.web.service.QueryControllerService;
28  import org.kuali.rice.krad.web.service.RefreshControllerService;
29  import org.kuali.rice.krad.web.service.SaveControllerService;
30  import org.springframework.beans.factory.annotation.Autowired;
31  import org.springframework.validation.BindingResult;
32  import org.springframework.web.bind.annotation.ModelAttribute;
33  import org.springframework.web.bind.annotation.RequestMapping;
34  import org.springframework.web.bind.annotation.RequestMethod;
35  import org.springframework.web.bind.annotation.ResponseBody;
36  import org.springframework.web.servlet.ModelAndView;
37  
38  import javax.servlet.http.HttpServletRequest;
39  import javax.servlet.http.HttpServletResponse;
40  import java.util.Map;
41  import java.util.Properties;
42  
43  /**
44   * Base controller class for views within the KRAD User Interface Framework.
45   *
46   * <p>Provides common methods such as navigation, collection handling, queries, and refresh calls.
47   *
48   * All subclass controller methods after processing should call one of the #getModelAndView methods to
49   * setup the {@link org.kuali.rice.krad.uif.view.View} and return the {@link org.springframework.web.servlet.ModelAndView}
50   * instance.</p>
51   *
52   * @author Kuali Rice Team (rice.collab@kuali.org)
53   */
54  public abstract class UifControllerBase {
55  
56      @Autowired
57      private ControllerService controllerService;
58  
59      @Autowired
60      private NavigationControllerService navigationControllerService;
61  
62      @Autowired
63      private CollectionControllerService collectionControllerService;
64  
65      @Autowired
66      private SaveControllerService saveControllerService;
67  
68      @Autowired
69      private RefreshControllerService refreshControllerService;
70  
71      @Autowired
72      private QueryControllerService queryControllerService;
73  
74      @Autowired
75      private FileControllerService fileControllerService;
76  
77      @Autowired
78      private ModelAndViewService modelAndViewService;
79  
80      /**
81       * Creates form instance the will be used for the default model.
82       *
83       * @return UifFormBase form instance for holding model data
84       */
85      @ModelAttribute(value = UifConstants.DEFAULT_MODEL_NAME)
86      protected UifFormBase initForm() {
87          return createInitialForm();
88      }
89  
90      /**
91       * Invoked to create a new form instance for the request before it is passed to the Binder/BeanWrapper.
92       *
93       * @return UifFormBase instance that will be used for data binding and backing the view.
94       */
95      protected abstract UifFormBase createInitialForm();
96  
97      /**
98       * Default method mapping for cases where the method to call is not passed, calls the start method.
99       */
100     @RequestMapping()
101     public ModelAndView defaultMapping(UifFormBase form) {
102         return start(form);
103     }
104 
105     /**
106      * @see org.kuali.rice.krad.web.service.ControllerService#start(org.kuali.rice.krad.web.form.UifFormBase)
107      */
108     @RequestMapping(method = RequestMethod.GET, params = "methodToCall=start")
109     public ModelAndView start(UifFormBase form) {
110         return getControllerService().start(form);
111     }
112 
113     /**
114      * @see org.kuali.rice.krad.web.service.ControllerService#sessionTimeout(org.kuali.rice.krad.web.form.UifFormBase)
115      */
116     @RequestMapping(params = "methodToCall=sessionTimeout")
117     public ModelAndView sessionTimeout(UifFormBase form) {
118         return getControllerService().sessionTimeout(form);
119     }
120 
121     /**
122      * @see org.kuali.rice.krad.web.service.ControllerService#cancel(org.kuali.rice.krad.web.form.UifFormBase)
123      */
124     @RequestMapping(params = "methodToCall=cancel")
125     public ModelAndView cancel(UifFormBase form) {
126         return getControllerService().cancel(form);
127     }
128 
129     /**
130      * @see org.kuali.rice.krad.web.service.NavigationControllerService#back(org.kuali.rice.krad.web.form.UifFormBase)
131      */
132     @RequestMapping(params = "methodToCall=back")
133     public ModelAndView back(UifFormBase form) {
134         return getNavigationControllerService().back(form);
135     }
136 
137     /**
138      * @see org.kuali.rice.krad.web.service.NavigationControllerService#returnToPrevious(org.kuali.rice.krad.web.form.UifFormBase)
139      */
140     @RequestMapping(params = "methodToCall=returnToPrevious")
141     public ModelAndView returnToPrevious(UifFormBase form) {
142         return getNavigationControllerService().returnToPrevious(form);
143     }
144 
145     /**
146      * @see org.kuali.rice.krad.web.service.SaveControllerService#save(org.kuali.rice.krad.web.form.UifFormBase)
147      */
148     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=save")
149     public ModelAndView save(UifFormBase form) throws Exception{
150         // Hook method for saving the form
151         return getSaveControllerService().save(form);
152     }
153 
154     /**
155      * @see org.kuali.rice.krad.web.service.SaveControllerService#saveField(org.kuali.rice.krad.web.form.UifFormBase)
156      */
157     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=saveField")
158     public ModelAndView saveField(UifFormBase form) throws Exception{
159         // Hook method for saving individual fields
160         return getSaveControllerService().saveField(form);
161     }
162 
163     /**
164      * @see org.kuali.rice.krad.web.service.NavigationControllerService#returnToHub(org.kuali.rice.krad.web.form.UifFormBase)
165      */
166     @RequestMapping(params = "methodToCall=returnToHub")
167     public ModelAndView returnToHub(UifFormBase form) {
168         return getNavigationControllerService().returnToHub(form);
169     }
170 
171     /**
172      * @see org.kuali.rice.krad.web.service.FileControllerService#addFileUploadLine(org.kuali.rice.krad.web.form.UifFormBase)
173      */
174     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addFileUploadLine")
175     public ModelAndView addFileUploadLine(UifFormBase form) {
176         return getFileControllerService().addFileUploadLine(form);
177     }
178 
179     /**
180      * @see org.kuali.rice.krad.web.service.FileControllerService#deleteFileUploadLine(org.kuali.rice.krad.web.form.UifFormBase)
181      */
182     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteFileUploadLine")
183     public ModelAndView deleteFileUploadLine(UifFormBase form) {
184         return getFileControllerService().deleteFileUploadLine(form);
185     }
186 
187     /**
188      * @see org.kuali.rice.krad.web.service.FileControllerService#getFileFromLine(org.kuali.rice.krad.web.form.UifFormBase,
189      * javax.servlet.http.HttpServletResponse)
190      */
191     @RequestMapping(method = RequestMethod.GET, params = "methodToCall=getFileFromLine")
192     public void getFileFromLine(UifFormBase form, HttpServletResponse response) {
193         getFileControllerService().getFileFromLine(form, response);
194     }
195 
196     /**
197      * @see org.kuali.rice.krad.web.service.NavigationControllerService#navigate(org.kuali.rice.krad.web.form.UifFormBase)
198      */
199     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=navigate")
200     public ModelAndView navigate(UifFormBase form) {
201         return getNavigationControllerService().navigate(form);
202     }
203 
204     /**
205      * @see org.kuali.rice.krad.web.service.CollectionControllerService#addLine(org.kuali.rice.krad.web.form.UifFormBase)
206      */
207     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addLine")
208     public ModelAndView addLine(UifFormBase form) {
209         return getCollectionControllerService().addLine(form);
210     }
211 
212     /**
213      * @see org.kuali.rice.krad.web.service.CollectionControllerService#addBlankLine(org.kuali.rice.krad.web.form.UifFormBase)
214      */
215     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addBlankLine")
216     public ModelAndView addBlankLine(UifFormBase form) {
217         return getCollectionControllerService().addBlankLine(form);
218     }
219 
220     /**
221      * @see org.kuali.rice.krad.web.service.CollectionControllerService#retrieveEditLineDialog(org.kuali.rice.krad.web.form.UifFormBase)
222      */
223     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=retrieveEditLineDialog")
224     public ModelAndView retrieveEditLineDialog(UifFormBase form) {
225         return getCollectionControllerService().retrieveEditLineDialog(form);
226     }
227 
228     /**
229      * @see org.kuali.rice.krad.web.service.CollectionControllerService#editLine(org.kuali.rice.krad.web.form.UifFormBase)
230      */
231     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=editLine")
232     public ModelAndView editLine(UifFormBase form) {
233         return getCollectionControllerService().editLine(form);
234     }
235 
236     /**
237      * @see org.kuali.rice.krad.web.service.CollectionControllerService#closeEditLineDialog(org.kuali.rice.krad.web.form.UifFormBase)
238      */
239     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=closeEditLineDialog")
240     public ModelAndView closeEditLineDialog(UifFormBase form) {
241         return getCollectionControllerService().closeEditLineDialog(form);
242     }
243 
244     /**
245      * @see org.kuali.rice.krad.web.service.CollectionControllerService#saveLine(org.kuali.rice.krad.web.form.UifFormBase)
246      */
247     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=saveLine")
248     public ModelAndView saveLine(UifFormBase form) {
249         return getCollectionControllerService().saveLine(form);
250     }
251 
252     /**
253      * @see org.kuali.rice.krad.web.service.CollectionControllerService#deleteLine(org.kuali.rice.krad.web.form.UifFormBase)
254      */
255     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=deleteLine")
256     public ModelAndView deleteLine(final UifFormBase form) {
257         return getCollectionControllerService().deleteLine(form);
258     }
259 
260     /**
261      * @see org.kuali.rice.krad.web.service.CollectionControllerService#retrieveCollectionPage(org.kuali.rice.krad.web.form.UifFormBase)
262      */
263     @RequestMapping(params = "methodToCall=retrieveCollectionPage")
264     public ModelAndView retrieveCollectionPage(UifFormBase form) {
265         return getCollectionControllerService().retrieveCollectionPage(form);
266     }
267 
268     /**
269      * @see org.kuali.rice.krad.web.service.CollectionControllerService#tableJsonRetrieval(org.kuali.rice.krad.web.form.UifFormBase)
270      */
271     @RequestMapping(method = RequestMethod.GET, params = "methodToCall=tableJsonRetrieval")
272     public ModelAndView tableJsonRetrieval(UifFormBase form) {
273         return getCollectionControllerService().tableJsonRetrieval(form);
274     }
275 
276     /**
277      * @see org.kuali.rice.krad.web.service.RefreshControllerService#refresh(org.kuali.rice.krad.web.form.UifFormBase)
278      */
279     @MethodAccessible
280     @RequestMapping(params = "methodToCall=refresh")
281     public ModelAndView refresh(UifFormBase form) {
282         return getRefreshControllerService().refresh(form);
283     }
284 
285     /**
286      * @see org.kuali.rice.krad.web.service.QueryControllerService#performLookup(org.kuali.rice.krad.web.form.UifFormBase)
287      */
288     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=performLookup")
289     public ModelAndView performLookup(UifFormBase form) {
290         return getQueryControllerService().performLookup(form);
291     }
292 
293     /**
294      * @see org.kuali.rice.krad.web.service.QueryControllerService#performFieldSuggest(org.kuali.rice.krad.web.form.UifFormBase)
295      */
296     @RequestMapping(method = RequestMethod.GET, params = "methodToCall=performFieldSuggest")
297     @ResponseBody
298     public AttributeQueryResult performFieldSuggest(UifFormBase form) {
299         return getQueryControllerService().performFieldSuggest(form);
300     }
301 
302     /**
303      * @see org.kuali.rice.krad.web.service.QueryControllerService#performFieldQuery(org.kuali.rice.krad.web.form.UifFormBase)
304      */
305     @RequestMapping(method = RequestMethod.GET, params = "methodToCall=performFieldQuery")
306     @ResponseBody
307     public AttributeQueryResult performFieldQuery(UifFormBase form) {
308         return getQueryControllerService().performFieldQuery(form);
309     }
310 
311     /**
312      * @see org.kuali.rice.krad.web.service.ModelAndViewService#checkForm(org.kuali.rice.krad.web.form.UifFormBase)
313      */
314     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=checkForm")
315     public ModelAndView checkForm(UifFormBase form) {
316         return getModelAndViewService().checkForm(form);
317     }
318 
319     /**
320      * @see org.kuali.rice.krad.web.service.ModelAndViewService#showDialog(java.lang.String, boolean,
321      * org.kuali.rice.krad.web.form.UifFormBase)
322      */
323     protected ModelAndView showDialog(String dialogId, boolean confirmation, UifFormBase form) {
324         return getModelAndViewService().showDialog(dialogId, confirmation, form);
325     }
326 
327     /**
328      * @see org.kuali.rice.krad.web.service.ModelAndViewService#performRedirect(org.kuali.rice.krad.web.form.UifFormBase,
329      * java.lang.String, java.util.Properties)
330      */
331     protected ModelAndView performRedirect(UifFormBase form, String baseUrl, Properties urlParameters) {
332         return getModelAndViewService().performRedirect(form, baseUrl, urlParameters);
333     }
334 
335     /**
336      * @see org.kuali.rice.krad.web.service.ModelAndViewService#performRedirect(org.kuali.rice.krad.web.form.UifFormBase,
337      * java.lang.String)
338      */
339     protected ModelAndView performRedirect(UifFormBase form, String redirectUrl) {
340         return getModelAndViewService().performRedirect(form, redirectUrl);
341     }
342 
343     /**
344      * @see org.kuali.rice.krad.web.service.ModelAndViewService#getMessageView(org.kuali.rice.krad.web.form.UifFormBase,
345      * java.lang.String, java.lang.String)
346      */
347     protected ModelAndView getMessageView(UifFormBase form, String headerText, String messageText) {
348         return getModelAndViewService().getMessageView(form, headerText, messageText);
349     }
350 
351     /**
352      * @see org.kuali.rice.krad.web.service.ModelAndViewService#getModelAndView(org.kuali.rice.krad.web.form.UifFormBase)
353      */
354     protected ModelAndView getModelAndView(UifFormBase form) {
355         return getModelAndViewService().getModelAndView(form);
356     }
357 
358     /**
359      * @see org.kuali.rice.krad.web.service.ModelAndViewService#getModelAndView(org.kuali.rice.krad.web.form.UifFormBase,
360      * java.lang.String)
361      */
362     protected ModelAndView getModelAndView(UifFormBase form, String pageId) {
363         return getModelAndViewService().getModelAndView(form, pageId);
364     }
365 
366     /**
367      * @see org.kuali.rice.krad.web.service.ModelAndViewService#getModelAndView(org.kuali.rice.krad.web.form.UifFormBase,
368      * java.util.Map<java.lang.String,java.lang.Object>)
369      */
370     protected ModelAndView getModelAndView(UifFormBase form, Map<String, Object> additionalViewAttributes) {
371         return getModelAndViewService().getModelAndView(form, additionalViewAttributes);
372     }
373 
374     /**
375      * @see org.kuali.rice.krad.web.service.ModelAndViewService#getModelAndViewWithInit(org.kuali.rice.krad.web.form.UifFormBase,
376      * java.lang.String)
377      */
378     protected ModelAndView getModelAndViewWithInit(UifFormBase form, String viewId) {
379         return getModelAndViewService().getModelAndViewWithInit(form, viewId);
380     }
381 
382     /**
383      * @see org.kuali.rice.krad.web.service.ModelAndViewService#getModelAndViewWithInit(org.kuali.rice.krad.web.form.UifFormBase,
384      * java.lang.String, java.lang.String)
385      */
386     protected ModelAndView getModelAndViewWithInit(UifFormBase form, String viewId, String pageId) {
387         return getModelAndViewService().getModelAndViewWithInit(form, viewId, pageId);
388     }
389 
390     protected ControllerService getControllerService() {
391         return controllerService;
392     }
393 
394     public void setControllerService(ControllerService controllerService) {
395         this.controllerService = controllerService;
396     }
397 
398     protected NavigationControllerService getNavigationControllerService() {
399         return navigationControllerService;
400     }
401 
402     public void setNavigationControllerService(NavigationControllerService navigationControllerService) {
403         this.navigationControllerService = navigationControllerService;
404     }
405 
406     protected CollectionControllerService getCollectionControllerService() {
407         return collectionControllerService;
408     }
409 
410     public void setCollectionControllerService(CollectionControllerService collectionControllerService) {
411         this.collectionControllerService = collectionControllerService;
412     }
413 
414     protected RefreshControllerService getRefreshControllerService() {
415         return refreshControllerService;
416     }
417 
418     public void setRefreshControllerService(RefreshControllerService refreshControllerService) {
419         this.refreshControllerService = refreshControllerService;
420     }
421 
422     public SaveControllerService getSaveControllerService() {
423         return saveControllerService;
424     }
425 
426     public void setSaveControllerService(SaveControllerService saveControllerService) {
427         this.saveControllerService = saveControllerService;
428     }
429 
430     protected QueryControllerService getQueryControllerService() {
431         return queryControllerService;
432     }
433 
434     public void setQueryControllerService(QueryControllerService queryControllerService) {
435         this.queryControllerService = queryControllerService;
436     }
437 
438     protected FileControllerService getFileControllerService() {
439         return fileControllerService;
440     }
441 
442     public void setFileControllerService(FileControllerService fileControllerService) {
443         this.fileControllerService = fileControllerService;
444     }
445 
446     protected ModelAndViewService getModelAndViewService() {
447         return modelAndViewService;
448     }
449 
450     public void setModelAndViewService(ModelAndViewService modelAndViewService) {
451         this.modelAndViewService = modelAndViewService;
452     }
453 }