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