1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.lifecycle;
17
18 import java.util.Map;
19
20 import javax.servlet.http.HttpServletRequest;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.rice.krad.uif.UifConstants;
24 import org.kuali.rice.krad.uif.UifParameters;
25 import org.kuali.rice.krad.uif.component.MethodInvokerConfig;
26 import org.kuali.rice.krad.uif.view.View;
27 import org.kuali.rice.krad.util.KRADConstants;
28 import org.kuali.rice.krad.web.controller.UifControllerBase;
29 import org.kuali.rice.krad.web.form.UifFormBase;
30 import org.springframework.web.servlet.support.RequestContextUtils;
31
32
33
34
35
36
37
38
39 public class ViewLifecycleRefreshBuild implements Runnable {
40
41 @Override
42 public void run() {
43 View view = ViewLifecycle.getView();
44 UifFormBase form = (UifFormBase) ViewLifecycle.getModel();
45 HttpServletRequest request = ViewLifecycle.getRequest();
46
47 String flashMapSelectedLineValues = "";
48 if (RequestContextUtils.getInputFlashMap(request) != null) {
49 flashMapSelectedLineValues = (String) RequestContextUtils.getInputFlashMap(request).get(
50 UifParameters.SELECTED_LINE_VALUES);
51 }
52
53 String refreshCallerType = "";
54 if (request.getParameterMap().containsKey(KRADConstants.REFRESH_CALLER_TYPE)) {
55 refreshCallerType = request.getParameter(KRADConstants.REFRESH_CALLER_TYPE);
56 }
57
58
59 if (StringUtils.equals(refreshCallerType, UifConstants.RefreshCallerTypes.MULTI_VALUE_LOOKUP)) {
60 String lookupCollectionName = "";
61 if (request.getParameterMap().containsKey(UifParameters.LOOKUP_COLLECTION_NAME)) {
62 lookupCollectionName = request.getParameter(UifParameters.LOOKUP_COLLECTION_NAME);
63 }
64
65 String lookupCollectionId = "";
66 if (request.getParameterMap().containsKey(UifParameters.LOOKUP_COLLECTION_ID)) {
67 lookupCollectionId = request.getParameter(UifParameters.LOOKUP_COLLECTION_ID);
68 }
69
70 if (StringUtils.isBlank(lookupCollectionName)) {
71 throw new RuntimeException(
72 "Lookup collection name is required for processing multi-value lookup results");
73 }
74
75 String multiValueReturnFields ="";
76 if (request.getParameterMap().containsKey(UifParameters.MULIT_VALUE_RETURN_FILEDS)) {
77 multiValueReturnFields = request.getParameter(UifParameters.MULIT_VALUE_RETURN_FILEDS);
78 }
79
80 String selectedLineValues = "";
81 if (request.getParameterMap().containsKey(UifParameters.SELECTED_LINE_VALUES)) {
82 selectedLineValues = request.getParameter(UifParameters.SELECTED_LINE_VALUES);
83 }
84 if (!StringUtils.isBlank(flashMapSelectedLineValues)) {
85 selectedLineValues = flashMapSelectedLineValues;
86 }
87
88
89 ViewLifecycle.getHelper().processMultipleValueLookupResults(form, lookupCollectionId,
90 lookupCollectionName, multiValueReturnFields, selectedLineValues);
91 }
92
93
94 if (request.getParameterMap().containsKey(KRADConstants.REFERENCES_TO_REFRESH)) {
95 String referencesToRefresh = request.getParameter(KRADConstants.REFERENCES_TO_REFRESH);
96
97 ViewLifecycle.getHelper().refreshReferences(referencesToRefresh);
98 }
99
100
101
102 if (request.getParameterMap().containsKey(UifParameters.QUICKFINDER_ID)) {
103 String quickfinderId = request.getParameter(UifParameters.QUICKFINDER_ID);
104
105 String focusId = (String) form.getViewPostMetadata().getComponentPostData(quickfinderId,
106 UifConstants.PostMetadata.QUICKFINDER_FOCUS_ID);
107 if (StringUtils.isNotBlank(focusId)) {
108 form.setFocusId(focusId);
109 }
110
111 String jumpToId = (String) form.getViewPostMetadata().getComponentPostData(quickfinderId,
112 UifConstants.PostMetadata.QUICKFINDER_JUMP_TO_ID);
113 if (StringUtils.isNotBlank(jumpToId)) {
114 form.setJumpToId(jumpToId);
115 }
116
117
118 String callbackMethodToCall = ( String ) form.getViewPostMetadata().getComponentPostData( quickfinderId,
119 UifConstants.PostMetadata.QUICKFINDER_CALLBACK_METHOD_TO_CALL );
120 MethodInvokerConfig callbackMethod = ( MethodInvokerConfig ) form.getViewPostMetadata().
121 getComponentPostData( quickfinderId, UifConstants.PostMetadata.QUICKFINDER_CALLBACK_METHOD );
122
123 if( StringUtils.isNotBlank( callbackMethodToCall ) || callbackMethod != null ) {
124
125 if( callbackMethod == null ) {
126 callbackMethod = new MethodInvokerConfig();
127 }
128
129
130 Map<String, String> callbackContext = ( Map<String, String> ) form.getViewPostMetadata().
131 getComponentPostData( quickfinderId, UifConstants.PostMetadata.QUICKFINDER_CALLBACK_CONTEXT );
132
133
134 if( ( callbackMethod.getTargetClass() == null ) && ( callbackMethod.getTargetObject() == null ) ) {
135 callbackMethod.setTargetObject( ViewLifecycle.getHelper() );
136 }
137
138 callbackMethod.setTargetMethod( callbackMethodToCall );
139 Object[] arguments = new Object[3];
140 arguments[0] = form;
141 arguments[1] = quickfinderId;
142 arguments[2] = callbackContext;
143 callbackMethod.setArguments( arguments );
144
145
146 try {
147 callbackMethod.prepare();
148
149 Class<?> methodReturnType = callbackMethod.getPreparedMethod().getReturnType();
150 if( StringUtils.equals( "void", methodReturnType.getName() ) ) {
151 callbackMethod.invoke();
152 } else {
153
154 }
155 } catch( Exception e ) {
156 throw new RuntimeException( "Error invoking callback method for quickfinder: " + quickfinderId, e );
157 }
158 }
159 }
160
161 }
162 }