001package org.kuali.rice.krad.web.controller.extension; 002 003import org.apache.commons.lang.StringUtils; 004import org.kuali.rice.krad.uif.UifConstants; 005import org.kuali.rice.krad.uif.view.View; 006import org.kuali.rice.krad.web.controller.UifControllerBase; 007import org.kuali.rice.krad.web.form.UifFormBase; 008import org.springframework.util.Assert; 009import org.springframework.web.servlet.ModelAndView; 010 011 012/** 013 * Fix under KSAP-265 014 * Used to replace krad FullView.ftl with ksapFullView.ftl 015 */ 016public abstract class KsapControllerBase extends UifControllerBase { 017 /** 018 * Configures the <code>ModelAndView</code> instance containing the form 019 * data and pointing to the UIF generic spring view 020 * 021 * @param form form instance containing the model data 022 * @param pageId id of the page within the view that should be rendered, can 023 * be left blank in which the current or default page is rendered 024 * @return ModelAndView object with the contained form 025 */ 026 @Override 027 protected ModelAndView getUIFModelAndView(UifFormBase form, String pageId) { 028 return getUIFModelAndViewHelper(form, pageId); 029 } 030 031 /** 032 * Retrieves a new view instance for the given view id and then configures the <code>ModelAndView</code> 033 * instance containing the form data and pointing to the UIF generic spring view 034 * 035 * @param form form instance containing the model data 036 * @param viewId id for the view that should be built 037 * @return ModelAndView object with the contained form 038 */ 039 @Override 040 protected ModelAndView getUIFModelAndViewWithInit(UifFormBase form, String viewId) { 041 View view = getViewService().getViewById(viewId); 042 043 Assert.notNull(view, "View not found with id: " + viewId); 044 045 form.setView(view); 046 form.setViewId(viewId); 047 048 return getUIFModelAndViewHelper(form, form.getPageId()); 049 } 050 051 /** 052 * Configures the <code>ModelAndView</code> instance containing the form 053 * data and pointing to the UIF generic spring view 054 * 055 * @param form - Form instance containing the model data 056 * @param pageId - Id of the page within the view that should be rendered, can 057 * be left blank in which the current or default page is rendered 058 * @return ModelAndView object with the contained form 059 */ 060 private static ModelAndView getUIFModelAndViewHelper(UifFormBase form, String pageId) { 061 if (StringUtils.isNotBlank(pageId)) { 062 form.setPageId(pageId); 063 } 064 065 // create the spring return object pointing to View.jsp 066 ModelAndView modelAndView = new ModelAndView(); 067 modelAndView.addObject(UifConstants.DEFAULT_MODEL_NAME, form); 068 modelAndView.setViewName("/krad/WEB-INF/ftl/ksapUifRender"); 069 070 return modelAndView; 071 } 072}