1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.web.struts.form;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.apache.struts.action.ActionMapping;
20 import org.kuali.rice.coreservice.framework.CoreFrameworkServiceLocator;
21 import org.kuali.rice.core.web.format.Formatter;
22 import org.kuali.rice.kns.datadictionary.HeaderNavigation;
23 import org.kuali.rice.kns.util.ActionFormUtilMap;
24 import org.kuali.rice.kns.util.WebUtils;
25 import org.kuali.rice.kns.web.struts.form.pojo.PojoFormBase;
26 import org.kuali.rice.kns.web.ui.ExtraButton;
27 import org.kuali.rice.kns.web.ui.HeaderField;
28 import org.kuali.rice.krad.util.KRADConstants;
29 import org.kuali.rice.krad.util.ObjectUtils;
30 import org.springframework.util.AutoPopulatingList;
31
32 import javax.servlet.ServletRequest;
33 import javax.servlet.http.HttpServletRequest;
34 import java.util.ArrayList;
35 import java.util.HashMap;
36 import java.util.List;
37 import java.util.Map;
38
39
40
41
42
43
44 @Deprecated
45 public class KualiForm extends PojoFormBase {
46
47
48
49 public static enum TabState {
50 OPEN,
51 CLOSE
52 }
53
54 private static final long serialVersionUID = 1L;
55
56 private static final String literalPrefixAndDelimiter =
57 KRADConstants.LOOKUP_PARAMETER_LITERAL_PREFIX+ KRADConstants.LOOKUP_PARAMETER_LITERAL_DELIMITER;
58
59 private String backLocation;
60 private String methodToCall;
61 private String refreshCaller;
62 private String anchor;
63 private Map<String, String> tabStates;
64 private Map actionFormUtilMap;
65 private Map displayedErrors = new HashMap();
66 private Map<String, Object> displayedWarnings = new HashMap<String, Object>();
67 private Map<String, Object> displayedInfo = new HashMap<String, Object>();
68 private int currentTabIndex = 0;
69 private int arbitrarilyHighIndex = 1000000;
70
71 private String navigationCss;
72 private HeaderNavigation[] headerNavigationTabs;
73 protected List<ExtraButton> extraButtons = new AutoPopulatingList( ExtraButton.class ) ;
74
75 private boolean fieldLevelHelpEnabled;
76
77 private List<HeaderField> docInfo;
78 private int numColumns = 2;
79
80 private String fieldNameToFocusOnAfterSubmit;
81
82
83
84
85 @Override
86 public void addRequiredNonEditableProperties(){
87 super.addRequiredNonEditableProperties();
88 registerRequiredNonEditableProperty(KRADConstants.REFRESH_CALLER);
89 }
90
91 public int getNumColumns() {
92 return this.numColumns;
93 }
94
95 public void setNumColumns(int numColumns) {
96 this.numColumns = numColumns;
97 }
98
99 public List<HeaderField> getDocInfo() {
100 return this.docInfo;
101 }
102
103 public void setDocInfo(List<HeaderField> docInfo) {
104 this.docInfo = docInfo;
105 }
106
107
108
109
110 public KualiForm() {
111 this.tabStates = new HashMap<String, String>();
112 this.actionFormUtilMap = new ActionFormUtilMap();
113 this.docInfo = new ArrayList<HeaderField>();
114 }
115
116
117
118
119 public void populate(HttpServletRequest request) {
120 setMethodToCall(WebUtils.parseMethodToCall(this, request));
121
122 super.populate(request);
123
124 populateBackLocation(request);
125 populateFieldLevelHelpEnabled(request);
126
127 if (actionFormUtilMap instanceof ActionFormUtilMap) {
128 ((ActionFormUtilMap) actionFormUtilMap).setCacheValueFinderResults(true);
129 }
130 }
131
132 private static Boolean ENABLE_FIELD_LEVEL_HELP_IND;
133
134 protected void populateBackLocation(HttpServletRequest request){
135 if (getParameter(request, "returnLocation") != null) {
136 setBackLocation(getParameter(request, "returnLocation"));
137 }
138 }
139
140
141
142
143
144
145
146 protected void populateFieldLevelHelpEnabled(HttpServletRequest request) {
147 boolean fieldLevelHelpEnabled = CoreFrameworkServiceLocator.getParameterService().getParameterValueAsBoolean(
148 KRADConstants.KNS_NAMESPACE, KRADConstants.DetailTypes.ALL_DETAIL_TYPE,
149 KRADConstants.SystemGroupParameterNames.ENABLE_FIELD_LEVEL_HELP_IND, Boolean.FALSE);
150 setFieldLevelHelpEnabled(fieldLevelHelpEnabled);
151 }
152
153 public Map getDisplayedErrors() {
154 return displayedErrors;
155 }
156
157
158
159
160 public Map<String, Object> getDisplayedWarnings() {
161 return this.displayedWarnings;
162 }
163
164
165
166
167 public Map<String, Object> getDisplayedInfo() {
168 return this.displayedInfo;
169 }
170
171
172
173
174
175
176 public String getMethodToCall() {
177 return methodToCall;
178 }
179
180
181
182
183
184 public void setMethodToCall(String methodToCall) {
185 this.methodToCall = methodToCall;
186 }
187
188
189
190
191
192
193
194 public String getRefreshCaller() {
195 return refreshCaller;
196 }
197
198
199
200
201
202 public void setRefreshCaller(String refreshCaller) {
203 this.refreshCaller = refreshCaller;
204 }
205
206
207
208
209 public Map<String, String> getTabStates() {
210 return tabStates;
211 }
212
213
214
215
216
217
218 public void setTabStates(Map<String, String> tabStates) {
219 this.tabStates = tabStates;
220 }
221
222
223
224
225 public String getTabState(String key) {
226 String state = KRADConstants.EMPTY_STRING;
227 if (tabStates.containsKey(key)) {
228 if (tabStates.get(key) instanceof String) {
229 state = tabStates.get(key);
230 }
231 else {
232
233
234 Object result = tabStates.get(key);
235 result.getClass();
236 state = ((String[])result)[0];
237 }
238 }
239
240 return state;
241 }
242
243 public int getCurrentTabIndex() {
244 return currentTabIndex;
245 }
246
247 public void setCurrentTabIndex(int currentTabIndex) {
248 this.currentTabIndex = currentTabIndex;
249 }
250
251 public void incrementTabIndex() {
252 this.currentTabIndex++;
253 }
254
255 public int getNextArbitrarilyHighIndex() {
256 return this.arbitrarilyHighIndex++;
257 }
258
259 public String getFieldNameToFocusOnAfterSubmit() {
260 return this.fieldNameToFocusOnAfterSubmit;
261 }
262
263 public void setFieldNameToFocusOnAfterSubmit(String fieldNameToFocusOnAfterSubmit) {
264 this.fieldNameToFocusOnAfterSubmit = fieldNameToFocusOnAfterSubmit;
265 }
266
267
268
269
270 public Map getActionFormUtilMap() {
271 return actionFormUtilMap;
272 }
273
274
275
276
277 public void setActionFormUtilMap(Map validOptionsMap) {
278 this.actionFormUtilMap = validOptionsMap;
279 }
280
281
282
283
284
285
286 public HeaderNavigation[] getHeaderNavigationTabs() {
287 return headerNavigationTabs;
288 }
289
290
291
292
293
294
295 public void setHeaderNavigationTabs(HeaderNavigation[] headerNavigationTabs) {
296 this.headerNavigationTabs = headerNavigationTabs;
297 }
298
299
300
301
302
303
304 public String getNavigationCss() {
305 return navigationCss;
306 }
307
308
309
310
311
312
313 public void setNavigationCss(String navigationCss) {
314 this.navigationCss = navigationCss;
315 }
316
317 public String getAnchor() {
318 return anchor;
319 }
320
321 public void setAnchor(String anchor) {
322 this.anchor = anchor;
323 }
324
325 public List<ExtraButton> getExtraButtons() {
326 return extraButtons;
327 }
328
329 public void setExtraButtons(List<ExtraButton> extraButtons) {
330 if ( extraButtons instanceof AutoPopulatingList ) {
331 this.extraButtons = extraButtons;
332 } else {
333 this.extraButtons.clear();
334 this.extraButtons.addAll( extraButtons );
335 }
336 }
337
338 public ExtraButton getExtraButton( int index ) {
339 return extraButtons.get( index );
340 }
341
342 public void setExtraButton( int index, ExtraButton extraButton ) {
343 extraButtons.set( index, extraButton );
344 }
345
346
347
348
349
350
351 public boolean isFieldLevelHelpEnabled() {
352 return this.fieldLevelHelpEnabled;
353 }
354
355 public void setFieldLevelHelpEnabled(boolean fieldLevelHelpEnabled) {
356 this.fieldLevelHelpEnabled = fieldLevelHelpEnabled;
357 }
358
359
360
361
362
363
364
365
366
367 public String retrieveFormValueForLookupInquiryParameters(String parameterName, String parameterValueLocation) {
368
369 if (parameterValueLocation.startsWith(literalPrefixAndDelimiter)) {
370 return parameterValueLocation.substring(literalPrefixAndDelimiter.length());
371 }
372
373 Object value = ObjectUtils.getPropertyValue(this, parameterValueLocation);
374 if (value == null) {
375 return null;
376 }
377 if (value instanceof String) {
378 return (String) value;
379 }
380 Formatter formatter = Formatter.getFormatter(value.getClass());
381 return (String) formatter.format(value);
382 }
383
384
385
386
387
388
389 @Override
390 public boolean shouldPropertyBePopulatedInForm(
391 String requestParameterName, HttpServletRequest request) {
392 if (requestParameterName.startsWith(KRADConstants.TAB_STATES)) {
393 return true;
394 }
395
396 if (requestParameterName.equals(KRADConstants.DISPATCH_REQUEST_PARAMETER)) {
397 String methodToCallParameterName = request.getParameter(KRADConstants.DISPATCH_REQUEST_PARAMETER);
398 if(StringUtils.equals(methodToCallParameterName, KRADConstants.RETURN_METHOD_TO_CALL)){
399 return true;
400 }
401 }
402
403 return super.shouldPropertyBePopulatedInForm(requestParameterName, request);
404 }
405
406 public boolean shouldMethodToCallParameterBeUsed(String methodToCallParameterName, String methodToCallParameterValue, HttpServletRequest request) {
407 if ("GET".equalsIgnoreCase(request.getMethod())) {
408 return true;
409 }
410 if (shouldPropertyBePopulatedInForm(methodToCallParameterName, request)) {
411 return true;
412 }
413 if (methodToCallParameterName != null && WebUtils.endsWithCoordinates(methodToCallParameterName)) {
414 methodToCallParameterName = methodToCallParameterName.substring(0, WebUtils.getIndexOfCoordinateExtension(methodToCallParameterName));
415 if (shouldPropertyBePopulatedInForm(methodToCallParameterName, request)) {
416 return true;
417 }
418 }
419 if (KRADConstants.METHOD_TO_CALL_PATH.equals(methodToCallParameterName)) {
420 if (shouldPropertyBePopulatedInForm(methodToCallParameterValue, request)) {
421 return true;
422 }
423 if (methodToCallParameterValue != null && WebUtils.endsWithCoordinates(methodToCallParameterName)) {
424 methodToCallParameterValue = methodToCallParameterValue.substring(0, WebUtils
425 .getIndexOfCoordinateExtension(methodToCallParameterName));
426 if (shouldPropertyBePopulatedInForm(methodToCallParameterValue, request)) {
427 return true;
428 }
429 }
430 }
431 return false;
432 }
433
434
435
436
437 @Override
438 public void clearEditablePropertyInformation() {
439 super.clearEditablePropertyInformation();
440 }
441
442 public void setDerivedValuesOnForm(HttpServletRequest request) {
443 }
444
445
446
447
448 @Override
449 public void reset(ActionMapping mapping, HttpServletRequest request) {
450 super.reset(mapping, request);
451 if (extraButtons != null) {
452 extraButtons.clear();
453 }
454
455 clearDisplayedMessages();
456 }
457
458
459
460
461 @Override
462 public void reset(ActionMapping mapping, ServletRequest request) {
463 super.reset(mapping, request);
464 if (extraButtons != null) {
465 extraButtons.clear();
466 }
467
468 clearDisplayedMessages();
469 }
470
471 private void clearDisplayedMessages() {
472 if (displayedErrors != null) {
473 displayedErrors.clear();
474 }
475 if (displayedWarnings != null) {
476 displayedWarnings.clear();
477 }
478 if (displayedInfo != null) {
479 displayedInfo.clear();
480 }
481 }
482
483
484
485
486 public String getBackLocation() {
487 return this.backLocation;
488 }
489
490
491
492
493 public void setBackLocation(String backLocation) {
494 this.backLocation = backLocation;
495 }
496
497 }