1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.util;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.log4j.Logger;
20 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
21 import org.kuali.rice.krad.uif.UifConstants;
22 import org.kuali.rice.krad.uif.view.History;
23 import org.kuali.rice.krad.uif.view.View;
24 import org.kuali.rice.krad.uif.component.Component;
25 import org.kuali.rice.krad.uif.service.ViewService;
26 import org.kuali.rice.krad.util.KRADUtils;
27 import org.kuali.rice.krad.web.controller.UifControllerBase;
28 import org.kuali.rice.krad.web.form.UifFormBase;
29 import org.springframework.web.servlet.ModelAndView;
30
31 import javax.servlet.http.HttpServletRequest;
32 import javax.servlet.http.HttpServletResponse;
33 import java.util.Map;
34
35
36
37
38
39
40
41
42
43
44 public class UifWebUtils {
45 private static final Logger LOG = Logger.getLogger(UifWebUtils.class);
46
47
48
49
50
51
52
53
54
55
56 public static ModelAndView getUIFModelAndView(UifFormBase form, String pageId) {
57 if (StringUtils.isNotBlank(pageId)) {
58 form.setPageId(pageId);
59 }
60
61
62 ModelAndView modelAndView = new ModelAndView();
63 modelAndView.addObject(UifConstants.DEFAULT_MODEL_NAME, form);
64 modelAndView.setViewName(UifConstants.SPRING_VIEW_ID);
65
66 return modelAndView;
67 }
68
69 public static ModelAndView getComponentModelAndView(Component component, Object model) {
70 ModelAndView modelAndView = new ModelAndView();
71 modelAndView.addObject(UifConstants.DEFAULT_MODEL_NAME, model);
72 modelAndView.addObject("Component", component);
73 modelAndView.setViewName("ComponentUpdate");
74
75 return modelAndView;
76 }
77
78
79
80
81
82 public static void postControllerHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
83 ModelAndView modelAndView) throws Exception {
84 if (handler instanceof UifControllerBase && (modelAndView != null)) {
85 UifControllerBase controller = (UifControllerBase) handler;
86 UifFormBase form = null;
87
88
89 if (modelAndView.getViewName().equals(UifConstants.SPRING_VIEW_ID)) {
90 Object model = modelAndView.getModelMap().get(UifConstants.DEFAULT_MODEL_NAME);
91 if (model instanceof UifFormBase) {
92 form = (UifFormBase) model;
93
94
95 prepareViewForRendering(request, form);
96
97
98 prepareHistory(request, form);
99 }
100 }
101 }
102 }
103
104
105
106
107
108
109
110
111 public static void prepareHistory(HttpServletRequest request, UifFormBase form) {
112 View view = form.getView();
113
114
115 History history = form.getFormHistory();
116 if (history == null || request.getMethod().equals("GET")) {
117 history = new History();
118 history.setHomewardPath(view.getBreadcrumbs().getHomewardPathList());
119 history.setAppendHomewardPath(view.getBreadcrumbs().isDisplayHomewardPath());
120 history.setAppendPassedHistory(view.getBreadcrumbs().isDisplayPassedHistory());
121
122
123 if (StringUtils.isNotBlank(request.getParameter(UifConstants.UrlParams.SHOW_HOME))) {
124 history.setAppendHomewardPath(Boolean.parseBoolean(request.getParameter(
125 UifConstants.UrlParams.SHOW_HOME)));
126 }
127
128 if (StringUtils.isNotBlank(request.getParameter(UifConstants.UrlParams.SHOW_HISTORY))) {
129 history.setAppendPassedHistory(Boolean.parseBoolean(request.getParameter(
130 UifConstants.UrlParams.SHOW_HISTORY)));
131 }
132
133 history.setCurrent(form, request);
134 history.buildHistoryFromParameterString(request.getParameter(UifConstants.UrlParams.HISTORY));
135 form.setFormHistory(history);
136 }
137 }
138
139
140
141
142
143
144
145
146 public static void prepareViewForRendering(HttpServletRequest request, UifFormBase form) {
147 View view = form.getView();
148
149
150 if (StringUtils.isNotBlank(form.getPageId())) {
151 view.setCurrentPageId(form.getPageId());
152 }
153
154 Map<String, String> parameterMap = KRADUtils.translateRequestParameterMap(request.getParameterMap());
155 parameterMap.putAll(form.getViewRequestParameters());
156
157
158 getViewService().buildView(view, form, parameterMap);
159
160
161 form.setValidateDirty(view.isValidateDirty());
162 }
163
164 protected static ViewService getViewService() {
165 return KRADServiceLocatorWeb.getViewService();
166 }
167 }