View Javadoc
1   package org.kuali.rice.krad.web.controller.extension;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.kuali.rice.krad.uif.UifConstants;
5   import org.kuali.rice.krad.uif.view.View;
6   import org.kuali.rice.krad.web.controller.UifControllerBase;
7   import org.kuali.rice.krad.web.form.UifFormBase;
8   import org.springframework.util.Assert;
9   import org.springframework.web.servlet.ModelAndView;
10  
11  
12  /**
13   * Fix under KSAP-265
14   * Used to replace krad FullView.ftl with ksapFullView.ftl
15   */
16  public abstract class KsapControllerBase extends UifControllerBase {
17      /**
18       * Configures the <code>ModelAndView</code> instance containing the form
19       * data and pointing to the UIF generic spring view
20       *
21       * @param form form instance containing the model data
22       * @param pageId id of the page within the view that should be rendered, can
23       * be left blank in which the current or default page is rendered
24       * @return ModelAndView object with the contained form
25       */
26      @Override
27      protected ModelAndView getUIFModelAndView(UifFormBase form, String pageId) {
28          return getUIFModelAndViewHelper(form, pageId);
29      }
30  
31      /**
32       * Retrieves a new view instance for the given view id and then configures the <code>ModelAndView</code>
33       * instance containing the form data and pointing to the UIF generic spring view
34       *
35       * @param form form instance containing the model data
36       * @param viewId id for the view that should be built
37       * @return ModelAndView object with the contained form
38       */
39      @Override
40      protected ModelAndView getUIFModelAndViewWithInit(UifFormBase form, String viewId) {
41          View view = getViewService().getViewById(viewId);
42  
43          Assert.notNull(view, "View not found with id: " + viewId);
44  
45          form.setView(view);
46          form.setViewId(viewId);
47  
48          return getUIFModelAndViewHelper(form, form.getPageId());
49      }
50  
51      /**
52       * Configures the <code>ModelAndView</code> instance containing the form
53       * data and pointing to the UIF generic spring view
54       *
55       * @param form - Form instance containing the model data
56       * @param pageId - Id of the page within the view that should be rendered, can
57       * be left blank in which the current or default page is rendered
58       * @return ModelAndView object with the contained form
59       */
60      private static ModelAndView getUIFModelAndViewHelper(UifFormBase form, String pageId) {
61          if (StringUtils.isNotBlank(pageId)) {
62              form.setPageId(pageId);
63          }
64  
65          // create the spring return object pointing to View.jsp
66          ModelAndView modelAndView = new ModelAndView();
67          modelAndView.addObject(UifConstants.DEFAULT_MODEL_NAME, form);
68          modelAndView.setViewName("/krad/WEB-INF/ftl/ksapUifRender");
69  
70          return modelAndView;
71      }
72  }