View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.uif.lifecycle;
17  
18  import javax.servlet.http.HttpServletRequest;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.kuali.rice.krad.uif.UifConstants;
22  import org.kuali.rice.krad.uif.UifParameters;
23  import org.kuali.rice.krad.uif.view.View;
24  import org.kuali.rice.krad.util.KRADConstants;
25  import org.kuali.rice.krad.web.controller.UifControllerBase;
26  import org.kuali.rice.krad.web.form.UifFormBase;
27  import org.springframework.web.servlet.support.RequestContextUtils;
28  
29  /**
30   * Lifecycle processing task for encapsulating a view refresh. 
31   * 
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   * @see ViewLifecycle#encapsulateLifecycle(View, Object, HttpServletRequest, javax.servlet.http.HttpServletResponse, Runnable)
34   * @see UifControllerBase#refresh(UifFormBase, org.springframework.validation.BindingResult, HttpServletRequest, javax.servlet.http.HttpServletResponse)
35   */
36  public class ViewLifecycleRefreshBuild implements Runnable {
37  
38      @Override
39      public void run() {
40          View view = ViewLifecycle.getView();
41          UifFormBase form = (UifFormBase) ViewLifecycle.getModel();
42          HttpServletRequest request = ViewLifecycle.getRequest();
43          
44          String flashMapSelectedLineValues = "";
45          if (RequestContextUtils.getInputFlashMap(request) != null) {
46              flashMapSelectedLineValues = (String) RequestContextUtils.getInputFlashMap(request).get(
47                      UifParameters.SELECTED_LINE_VALUES);
48          }
49  
50          String refreshCallerType = "";
51          if (request.getParameterMap().containsKey(KRADConstants.REFRESH_CALLER_TYPE)) {
52              refreshCallerType = request.getParameter(KRADConstants.REFRESH_CALLER_TYPE);
53          }
54  
55          // process multi-value lookup returns
56          if (StringUtils.equals(refreshCallerType, UifConstants.RefreshCallerTypes.MULTI_VALUE_LOOKUP)) {
57              String lookupCollectionName = "";
58              if (request.getParameterMap().containsKey(UifParameters.LOOKUP_COLLECTION_NAME)) {
59                  lookupCollectionName = request.getParameter(UifParameters.LOOKUP_COLLECTION_NAME);
60              }
61  
62              String lookupCollectionId = "";
63              if (request.getParameterMap().containsKey(UifParameters.LOOKUP_COLLECTION_ID)) {
64                  lookupCollectionId = request.getParameter(UifParameters.LOOKUP_COLLECTION_ID);
65              }
66  
67              if (StringUtils.isBlank(lookupCollectionName)) {
68                  throw new RuntimeException(
69                          "Lookup collection name is required for processing multi-value lookup results");
70              }
71  
72              String multiValueReturnFields ="";
73              if (request.getParameterMap().containsKey(UifParameters.MULIT_VALUE_RETURN_FILEDS)) {
74                  multiValueReturnFields = request.getParameter(UifParameters.MULIT_VALUE_RETURN_FILEDS);
75              }
76  
77              String selectedLineValues = "";
78              if (request.getParameterMap().containsKey(UifParameters.SELECTED_LINE_VALUES)) {
79                  selectedLineValues = request.getParameter(UifParameters.SELECTED_LINE_VALUES);
80              }
81              if (!StringUtils.isBlank(flashMapSelectedLineValues)) {
82                  selectedLineValues = flashMapSelectedLineValues;
83              }
84  
85              // invoked view helper to populate the collection from lookup results
86              ViewLifecycle.getHelper().processMultipleValueLookupResults(form, lookupCollectionId,
87                      lookupCollectionName, multiValueReturnFields, selectedLineValues);
88          }
89  
90          // refresh references
91          if (request.getParameterMap().containsKey(KRADConstants.REFERENCES_TO_REFRESH)) {
92              String referencesToRefresh = request.getParameter(KRADConstants.REFERENCES_TO_REFRESH);
93  
94              ViewLifecycle.getHelper().refreshReferences(referencesToRefresh);
95          }
96  
97          // set focus and jump position for returning from a quickfinder
98          if (request.getParameterMap().containsKey(UifParameters.QUICKFINDER_ID)) {
99              String quickfinderId = request.getParameter(UifParameters.QUICKFINDER_ID);
100 
101             String focusId = (String) form.getViewPostMetadata().getComponentPostData(quickfinderId,
102                                 UifConstants.PostMetadata.QUICKFINDER_FOCUS_ID);
103             if (StringUtils.isNotBlank(focusId)) {
104                 form.setFocusId(focusId);
105             }
106 
107             String jumpToId = (String) form.getViewPostMetadata().getComponentPostData(quickfinderId,
108                                 UifConstants.PostMetadata.QUICKFINDER_JUMP_TO_ID);
109             if (StringUtils.isNotBlank(jumpToId)) {
110                 form.setJumpToId(jumpToId);
111             }
112         }
113 
114     }
115 }