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