View Javadoc

1   /**
2    * Copyright 2005-2013 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.web.form;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.apache.commons.logging.Log;
20  import org.apache.commons.logging.LogFactory;
21  import org.codehaus.jackson.map.ObjectMapper;
22  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
23  import org.kuali.rice.krad.uif.UifConstants;
24  import org.kuali.rice.krad.uif.UifConstants.ViewType;
25  import org.kuali.rice.krad.uif.UifParameters;
26  import org.kuali.rice.krad.uif.service.ViewService;
27  import org.kuali.rice.krad.uif.util.SessionTransient;
28  import org.kuali.rice.krad.uif.view.DialogManager;
29  import org.kuali.rice.krad.uif.view.History;
30  import org.kuali.rice.krad.uif.view.View;
31  import org.kuali.rice.krad.uif.view.ViewModel;
32  import org.kuali.rice.krad.util.KRADUtils;
33  import org.springframework.web.multipart.MultipartFile;
34  
35  import javax.servlet.http.HttpServletRequest;
36  import java.io.IOException;
37  import java.util.ArrayList;
38  import java.util.HashMap;
39  import java.util.List;
40  import java.util.Map;
41  import java.util.Properties;
42  import java.util.Set;
43  import java.util.UUID;
44  
45  /**
46   * Base form class for views within the KRAD User Interface Framework
47   *
48   * <p>
49   * Holds properties necessary to determine the {@code View} instance that
50   * will be used to render the UI
51   * </p>
52   *
53   * @author Kuali Rice Team (rice.collab@kuali.org)
54   */
55  public class UifFormBase implements ViewModel {
56      private static final long serialVersionUID = 8432543267099454434L;
57  
58      // logger
59      private static final Log LOG = LogFactory.getLog(UifFormBase.class);
60  
61      // current view
62      protected String viewId;
63      protected String viewName;
64      protected ViewType viewTypeName;
65      protected String pageId;
66      protected String methodToCall;
67      protected String formKey;
68  
69      @SessionTransient
70      protected String jumpToId;
71      @SessionTransient
72      protected String jumpToName;
73      @SessionTransient
74      protected String focusId;
75  
76      protected String formPostUrl;
77      protected String controllerMapping;
78  
79      @SessionTransient
80      private Map<String, String> requestParameters;
81  
82      protected String state;
83      protected boolean defaultsApplied;
84      protected boolean renderedInLightBox;
85  
86      @SessionTransient
87      protected String growlScript;
88      @SessionTransient
89      protected String lightboxScript;
90  
91      protected View view;
92      protected View postedView;
93  
94      protected Map<String, String> viewRequestParameters;
95      protected List<String> readOnlyFieldsList;
96      protected Map<String, Object> newCollectionLines;
97  
98      @SessionTransient
99      protected Map<String, String> actionParameters;
100     protected Map<String, Object> clientStateForSyncing;
101     @SessionTransient
102     protected Map<String, Set<String>> selectedCollectionLines;
103 
104     protected List<Object> addedCollectionItems;
105 
106     @SessionTransient
107     protected MultipartFile attachmentFile;
108 
109     // navigation
110     protected String returnLocation;
111     protected String returnFormKey;
112 
113     @SessionTransient
114     protected boolean ajaxRequest;
115     @SessionTransient
116     protected String ajaxReturnType;
117 
118     protected History formHistory;
119 
120     // dialog fields
121     @SessionTransient
122     protected String dialogExplanation;
123     @SessionTransient
124     protected String dialogResponse;
125     protected DialogManager dialogManager;
126 
127     @SessionTransient
128     protected boolean requestRedirected;
129     @SessionTransient
130     protected String updateComponentId;
131 
132     protected Map<String, Object> extensionData;
133 
134     public UifFormBase() {
135         formKey = generateFormKey();
136         defaultsApplied = false;
137         renderedInLightBox = false;
138         requestRedirected = false;
139 
140         readOnlyFieldsList = new ArrayList<String>();
141         viewRequestParameters = new HashMap<String, String>();
142         newCollectionLines = new HashMap<String, Object>();
143         actionParameters = new HashMap<String, String>();
144         clientStateForSyncing = new HashMap<String, Object>();
145         selectedCollectionLines = new HashMap<String, Set<String>>();
146         addedCollectionItems = new ArrayList();
147         dialogManager = new DialogManager();
148         extensionData = new HashMap<String, Object>();
149     }
150 
151     /**
152      * Creates the unique id used to store this "conversation" in the session.
153      * The default method generates a java UUID.
154      *
155      * @return
156      */
157     protected String generateFormKey() {
158         return UUID.randomUUID().toString();
159     }
160 
161     /**
162      * @see org.kuali.rice.krad.uif.view.ViewModel#postBind(javax.servlet.http.HttpServletRequest)
163      */
164     @Override
165     public void postBind(HttpServletRequest request) {
166         // default form post URL to request URL
167         formPostUrl = request.getRequestURL().toString();
168 
169         //set controller mapping property
170         controllerMapping = request.getPathInfo();
171 
172         // get any sent client view state and parse into map
173         if (request.getParameterMap().containsKey(UifParameters.CLIENT_VIEW_STATE)) {
174             String clientStateJSON = request.getParameter(UifParameters.CLIENT_VIEW_STATE);
175             if (StringUtils.isNotBlank(clientStateJSON)) {
176                 // change single quotes to double quotes (necessary because the reverse was done for sending)
177                 clientStateJSON = StringUtils.replace(clientStateJSON, "'", "\"");
178 
179                 ObjectMapper mapper = new ObjectMapper();
180                 try {
181                     clientStateForSyncing = mapper.readValue(clientStateJSON, Map.class);
182                 } catch (IOException e) {
183                     throw new RuntimeException("Unable to decode client side state JSON", e);
184                 }
185             }
186         }
187 
188         // populate read only fields list
189         if (request.getParameter(UifParameters.READ_ONLY_FIELDS) != null) {
190             String readOnlyFields = request.getParameter(UifParameters.READ_ONLY_FIELDS);
191             setReadOnlyFieldsList(KRADUtils.convertStringParameterToList(readOnlyFields));
192         }
193     }
194 
195     /**
196      * @see org.kuali.rice.krad.uif.view.ViewModel#getViewId()
197      */
198     @Override
199     public String getViewId() {
200         return this.viewId;
201     }
202 
203     /**
204      * @see org.kuali.rice.krad.uif.view.ViewModel#setViewId(java.lang.String)
205      */
206     @Override
207     public void setViewId(String viewId) {
208         this.viewId = viewId;
209     }
210 
211     /**
212      * @see org.kuali.rice.krad.uif.view.ViewModel#getViewName()
213      */
214     @Override
215     public String getViewName() {
216         return this.viewName;
217     }
218 
219     /**
220      * @see org.kuali.rice.krad.uif.view.ViewModel#setViewName(java.lang.String)
221      */
222     @Override
223     public void setViewName(String viewName) {
224         this.viewName = viewName;
225     }
226 
227     /**
228      * @see org.kuali.rice.krad.uif.view.ViewModel#getViewTypeName()
229      */
230     @Override
231     public ViewType getViewTypeName() {
232         return this.viewTypeName;
233     }
234 
235     /**
236      * @see org.kuali.rice.krad.uif.view.ViewModel#setViewTypeName(org.kuali.rice.krad.uif.UifConstants.ViewType)
237      */
238     @Override
239     public void setViewTypeName(ViewType viewTypeName) {
240         this.viewTypeName = viewTypeName;
241     }
242 
243     /**
244      * @see org.kuali.rice.krad.uif.view.ViewModel#getPageId()
245      */
246     @Override
247     public String getPageId() {
248         return this.pageId;
249     }
250 
251     /**
252      * @see org.kuali.rice.krad.uif.view.ViewModel#setPageId(java.lang.String)
253      */
254     @Override
255     public void setPageId(String pageId) {
256         this.pageId = pageId;
257     }
258 
259     /**
260      * @see org.kuali.rice.krad.uif.view.ViewModel#getFormPostUrl()
261      */
262     @Override
263     public String getFormPostUrl() {
264         return this.formPostUrl;
265     }
266 
267     /**
268      * @see org.kuali.rice.krad.uif.view.ViewModel#setFormPostUrl(java.lang.String)
269      */
270     @Override
271     public void setFormPostUrl(String formPostUrl) {
272         this.formPostUrl = formPostUrl;
273     }
274 
275     /**
276      * Name of the controllerMapping for this form (includes slash)
277      *
278      * @return the controllerMapping string
279      */
280     public String getControllerMapping() {
281         return controllerMapping;
282     }
283 
284     /**
285      * The requestParameters represent all the parameters in the query string that were initially passed to this View
286      * by the initial request
287      *
288      * @return the requestParameters
289      */
290     public Map<String, String> getRequestParameters() {
291         return requestParameters;
292     }
293 
294     /**
295      * Set the requestParameters
296      *
297      * @param requestParameters
298      */
299     public void setRequestParameters(Map<String, String> requestParameters) {
300         this.requestParameters = requestParameters;
301     }
302 
303     public String getReturnLocation() {
304         return this.returnLocation;
305     }
306 
307     public void setReturnLocation(String returnLocation) {
308         this.returnLocation = returnLocation;
309     }
310 
311     public String getReturnFormKey() {
312         return this.returnFormKey;
313     }
314 
315     public void setReturnFormKey(String returnFormKey) {
316         this.returnFormKey = returnFormKey;
317     }
318 
319     /**
320      * Identifies the controller method that should be invoked to fulfill a
321      * request. The value will be matched up against the 'params' setting on the
322      * {@code RequestMapping} annotation for the controller method
323      *
324      * @return String method to call
325      */
326     public String getMethodToCall() {
327         return this.methodToCall;
328     }
329 
330     /**
331      * Setter for the method to call
332      *
333      * @param methodToCall
334      */
335     public void setMethodToCall(String methodToCall) {
336         this.methodToCall = methodToCall;
337     }
338 
339     /**
340      * @see org.kuali.rice.krad.uif.view.ViewModel#getViewRequestParameters()
341      */
342     @Override
343     public Map<String, String> getViewRequestParameters() {
344         return this.viewRequestParameters;
345     }
346 
347     /**
348      * @see org.kuali.rice.krad.uif.view.ViewModel#setViewRequestParameters(java.util.Map<java.lang.String,java.lang.String>)
349      */
350     @Override
351     public void setViewRequestParameters(Map<String, String> viewRequestParameters) {
352         this.viewRequestParameters = viewRequestParameters;
353     }
354 
355     /**
356      * @see org.kuali.rice.krad.uif.view.ViewModel#getReadOnlyFieldsList()
357      */
358     @Override
359     public List<String> getReadOnlyFieldsList() {
360         return readOnlyFieldsList;
361     }
362 
363     /**
364      * @see org.kuali.rice.krad.uif.view.ViewModel#setReadOnlyFieldsList(java.util.List<java.lang.String>)
365      */
366     @Override
367     public void setReadOnlyFieldsList(List<String> readOnlyFieldsList) {
368         this.readOnlyFieldsList = readOnlyFieldsList;
369     }
370 
371     /**
372      * @see org.kuali.rice.krad.uif.view.ViewModel#getNewCollectionLines()
373      */
374     @Override
375     public Map<String, Object> getNewCollectionLines() {
376         return this.newCollectionLines;
377     }
378 
379     /**
380      * @see org.kuali.rice.krad.uif.view.ViewModel#setNewCollectionLines(java.util.Map<java.lang.String,java.lang.Object>)
381      */
382     @Override
383     public void setNewCollectionLines(Map<String, Object> newCollectionLines) {
384         this.newCollectionLines = newCollectionLines;
385     }
386 
387     /**
388      * @see org.kuali.rice.krad.uif.view.ViewModel#getActionParameters()
389      */
390     @Override
391     public Map<String, String> getActionParameters() {
392         return this.actionParameters;
393     }
394 
395     /**
396      * Returns the action parameters map as a {@code Properties} instance
397      *
398      * @return Properties action parameters
399      */
400     public Properties getActionParametersAsProperties() {
401         return KRADUtils.convertMapToProperties(actionParameters);
402     }
403 
404     /**
405      * @see org.kuali.rice.krad.uif.view.ViewModel#setActionParameters(java.util.Map<java.lang.String,java.lang.String>)
406      */
407     @Override
408     public void setActionParameters(Map<String, String> actionParameters) {
409         this.actionParameters = actionParameters;
410     }
411 
412     /**
413      * Retrieves the value for the given action parameter, or empty string if
414      * not found
415      *
416      * @param actionParameterName - name of the action parameter to retrieve value for
417      * @return String parameter value or empty string
418      */
419     public String getActionParamaterValue(String actionParameterName) {
420         if ((actionParameters != null) && actionParameters.containsKey(actionParameterName)) {
421             return actionParameters.get(actionParameterName);
422         }
423 
424         return "";
425     }
426 
427     /**
428      * Returns the action event that was sent in the action parameters (if any)
429      *
430      * <p>
431      * The action event is a special action parameter that can be sent to indicate a type of action being taken. This
432      * can be looked at by the view or components to render differently
433      * </p>
434      *
435      * TODO: make sure action parameters are getting reinitialized on each request
436      *
437      * @return String action event name or blank if action event was not sent
438      */
439     public String getActionEvent() {
440         if ((actionParameters != null) && actionParameters.containsKey(UifConstants.UrlParams.ACTION_EVENT)) {
441             return actionParameters.get(UifConstants.UrlParams.ACTION_EVENT);
442         }
443 
444         return "";
445     }
446 
447     /**
448      * @see org.kuali.rice.krad.uif.view.ViewModel#getClientStateForSyncing()
449      */
450     @Override
451     public Map<String, Object> getClientStateForSyncing() {
452         return clientStateForSyncing;
453     }
454 
455     /**
456      * Setter for the client state
457      *
458      * @param clientStateForSyncing
459      */
460     public void setClientStateForSyncing(Map<String, Object> clientStateForSyncing) {
461         this.clientStateForSyncing = clientStateForSyncing;
462     }
463 
464     /**
465      * @see org.kuali.rice.krad.uif.view.ViewModel#getSelectedCollectionLines()
466      */
467     @Override
468     public Map<String, Set<String>> getSelectedCollectionLines() {
469         return selectedCollectionLines;
470     }
471 
472     /**
473      * @see org.kuali.rice.krad.uif.view.ViewModel#setSelectedCollectionLines(java.util.Map<java.lang.String,java.util.Set<java.lang.String>>)
474      */
475     @Override
476     public void setSelectedCollectionLines(Map<String, Set<String>> selectedCollectionLines) {
477         this.selectedCollectionLines = selectedCollectionLines;
478     }
479 
480     /**
481      * Key string that identifies the form instance in session storage
482      *
483      * <p>
484      * When the view is posted, the previous form instance is retrieved and then
485      * populated from the request parameters. This key string is retrieve the
486      * session form from the session service
487      * </p>
488      *
489      * @return String form session key
490      */
491     public String getFormKey() {
492         return this.formKey;
493     }
494 
495     /**
496      * Setter for the form's session key
497      *
498      * @param formKey
499      */
500     public void setFormKey(String formKey) {
501         this.formKey = formKey;
502     }
503 
504     /**
505      * @see org.kuali.rice.krad.uif.view.ViewModel#isDefaultsApplied()
506      */
507     @Override
508     public boolean isDefaultsApplied() {
509         return this.defaultsApplied;
510     }
511 
512     /**
513      * @see org.kuali.rice.krad.uif.view.ViewModel#setDefaultsApplied(boolean)
514      */
515     @Override
516     public void setDefaultsApplied(boolean defaultsApplied) {
517         this.defaultsApplied = defaultsApplied;
518     }
519 
520     /**
521      * Indicates whether a redirect has been requested for the view
522      *
523      * @return boolean true if redirect was requested, false if not
524      */
525     public boolean isRequestRedirected() {
526         return requestRedirected;
527     }
528 
529     /**
530      * Setter for the request redirect indicator
531      *
532      * @param requestRedirected
533      */
534     public void setRequestRedirected(boolean requestRedirected) {
535         this.requestRedirected = requestRedirected;
536     }
537 
538     /**
539      * Holder for files that are attached through the view
540      *
541      * @return MultipartFile representing the attachment
542      */
543     public MultipartFile getAttachmentFile() {
544         return this.attachmentFile;
545     }
546 
547     /**
548      * Setter for the form's attachment file
549      *
550      * @param attachmentFile
551      */
552     public void setAttachmentFile(MultipartFile attachmentFile) {
553         this.attachmentFile = attachmentFile;
554     }
555 
556     /**
557      * Id for the component that should be updated for a component refresh process
558      *
559      * @return String component id
560      */
561     public String getUpdateComponentId() {
562         return updateComponentId;
563     }
564 
565     /**
566      * Setter for the component id that should be refreshed
567      *
568      * @param updateComponentId
569      */
570     public void setUpdateComponentId(String updateComponentId) {
571         this.updateComponentId = updateComponentId;
572     }
573 
574     /**
575      * @see org.kuali.rice.krad.uif.view.ViewModel#getView()
576      */
577     @Override
578     public View getView() {
579         return this.view;
580     }
581 
582     /**
583      * @see org.kuali.rice.krad.uif.view.ViewModel#setView(org.kuali.rice.krad.uif.view.View)
584      */
585     @Override
586     public void setView(View view) {
587         this.view = view;
588     }
589 
590     /**
591      * @see org.kuali.rice.krad.uif.view.ViewModel#getPostedView()
592      */
593     @Override
594     public View getPostedView() {
595         return this.postedView;
596     }
597 
598     /**
599      * @see org.kuali.rice.krad.uif.view.ViewModel#setPostedView(org.kuali.rice.krad.uif.view.View)
600      */
601     @Override
602     public void setPostedView(View postedView) {
603         this.postedView = postedView;
604     }
605 
606     /**
607      * Instance of the {@code ViewService} that can be used to retrieve
608      * {@code View} instances
609      *
610      * @return ViewService implementation
611      */
612     protected ViewService getViewService() {
613         return KRADServiceLocatorWeb.getViewService();
614     }
615 
616     /**
617      * The jumpToId for this form, the element with this id will be jumped to automatically
618      * when the form is loaded in the view.
619      * Using "TOP" or "BOTTOM" will jump to the top or the bottom of the resulting page.
620      * jumpToId always takes precedence over jumpToName, if set.
621      *
622      * @return the jumpToId
623      */
624     public String getJumpToId() {
625         return this.jumpToId;
626     }
627 
628     /**
629      * @param jumpToId the jumpToId to set
630      */
631     public void setJumpToId(String jumpToId) {
632         this.jumpToId = jumpToId;
633     }
634 
635     /**
636      * The jumpToName for this form, the element with this name will be jumped to automatically
637      * when the form is loaded in the view.
638      * WARNING: jumpToId always takes precedence over jumpToName, if set.
639      *
640      * @return the jumpToName
641      */
642     public String getJumpToName() {
643         return this.jumpToName;
644     }
645 
646     /**
647      * @param jumpToName the jumpToName to set
648      */
649     public void setJumpToName(String jumpToName) {
650         this.jumpToName = jumpToName;
651     }
652 
653     /**
654      * Field to place focus on when the page loads
655      * An empty focusId will result in focusing on the first visible input element by default.
656      *
657      * @return the focusId
658      */
659     public String getFocusId() {
660         return this.focusId;
661     }
662 
663     /**
664      * @param focusId the focusId to set
665      */
666     public void setFocusId(String focusId) {
667         this.focusId = focusId;
668     }
669 
670     /**
671      * History parameter representing the History of views that have come before the
672      * viewing of the current view
673      *
674      * <p>
675      * Used for breadcrumb widget generation on the view and also for navigating back
676      * to previous or hub locations
677      * </p>
678      *
679      * @return History instance giving current history
680      */
681     public History getFormHistory() {
682         return formHistory;
683     }
684 
685     /**
686      * Setter for the current History object
687      *
688      * @param history the history to set
689      */
690     public void setFormHistory(History history) {
691         this.formHistory = history;
692     }
693 
694     /**
695      * Indicates whether the view is rendered within a lightbox
696      *
697      * <p>
698      * Some discussion (for example how a close button behaves) need to change based on whether the
699      * view is rendered within a lightbox or the standard browser window. This boolean is true when it is
700      * within a lightbox
701      * </p>
702      *
703      * @return boolean true if view is rendered within a lightbox, false if not
704      */
705     public boolean isRenderedInLightBox() {
706         return this.renderedInLightBox;
707     }
708 
709     /**
710      * Setter for the rendered within lightbox indicator
711      *
712      * @param renderedInLightBox
713      */
714     public void setRenderedInLightBox(boolean renderedInLightBox) {
715         this.renderedInLightBox = renderedInLightBox;
716     }
717 
718     /**
719      * @see org.kuali.rice.krad.uif.view.ViewModel#getGrowlScript()
720      */
721     @Override
722     public String getGrowlScript() {
723         return growlScript;
724     }
725 
726     /**
727      * @see org.kuali.rice.krad.uif.view.ViewModel#setGrowlScript(java.lang.String)
728      */
729     @Override
730     public void setGrowlScript(String growlScript) {
731         this.growlScript = growlScript;
732     }
733 
734     /**
735      * @see org.kuali.rice.krad.uif.view.ViewModel#getState()
736      */
737     public String getState() {
738         return state;
739     }
740 
741     /**
742      * @see ViewModel#setState(String)
743      */
744     public void setState(String state) {
745         this.state = state;
746     }
747 
748     /**
749      * @see org.kuali.rice.krad.uif.view.ViewModel#getLightboxScript()
750      */
751     @Override
752     public String getLightboxScript() {
753         return lightboxScript;
754     }
755 
756     /**
757      * @see org.kuali.rice.krad.uif.view.ViewModel#setLightboxScript(java.lang.String)
758      */
759     @Override
760     public void setLightboxScript(String lightboxScript) {
761         this.lightboxScript = lightboxScript;
762     }
763 
764     /**
765      * @see org.kuali.rice.krad.uif.view.ViewModel#isAjaxRequest()
766      */
767     @Override
768     public boolean isAjaxRequest() {
769         return ajaxRequest;
770     }
771 
772     /**
773      * @see org.kuali.rice.krad.uif.view.ViewModel#setAjaxRequest(boolean)
774      */
775     @Override
776     public void setAjaxRequest(boolean ajaxRequest) {
777         this.ajaxRequest = ajaxRequest;
778     }
779 
780     /**
781      * @see org.kuali.rice.krad.uif.view.ViewModel#getAjaxReturnType()
782      */
783     @Override
784     public String getAjaxReturnType() {
785         return ajaxReturnType;
786     }
787 
788     /**
789      * @see org.kuali.rice.krad.uif.view.ViewModel#isUpdateComponentRequest()
790      */
791     @Override
792     public boolean isUpdateComponentRequest() {
793         return isAjaxRequest() && StringUtils.isNotBlank(getAjaxReturnType()) && getAjaxReturnType().equals(
794                 UifConstants.AjaxReturnTypes.UPDATECOMPONENT.getKey());
795     }
796 
797     /**
798      * @see org.kuali.rice.krad.uif.view.ViewModel#isUpdateDialogRequest()
799      */
800     @Override
801     public boolean isUpdateDialogRequest() {
802         return isAjaxRequest() && StringUtils.isNotBlank(getAjaxReturnType()) && getAjaxReturnType().equals(
803                 UifConstants.AjaxReturnTypes.UPDATEDIALOG.getKey());
804     }
805 
806     /**
807      * @see org.kuali.rice.krad.uif.view.ViewModel#isUpdatePageRequest()
808      */
809     @Override
810     public boolean isUpdatePageRequest() {
811         return isAjaxRequest() && StringUtils.isNotBlank(getAjaxReturnType()) && getAjaxReturnType().equals(
812                 UifConstants.AjaxReturnTypes.UPDATEPAGE.getKey());
813     }
814 
815     /**
816      * @see org.kuali.rice.krad.uif.view.ViewModel#isUpdateNoneRequest()
817      */
818     @Override
819     public boolean isUpdateNoneRequest() {
820         return isAjaxRequest() && StringUtils.isNotBlank(getAjaxReturnType()) && getAjaxReturnType().equals(
821                 UifConstants.AjaxReturnTypes.UPDATENONE.getKey());
822     }
823 
824     /**
825      * @see org.kuali.rice.krad.uif.view.ViewModel#isBuildViewRequest()
826      */
827     @Override
828     public boolean isBuildViewRequest() {
829         return !isAjaxRequest() || (StringUtils.isNotBlank(getAjaxReturnType()) && (getAjaxReturnType().equals(
830                 UifConstants.AjaxReturnTypes.UPDATEVIEW.getKey()) || isUpdatePageRequest()));
831     }
832 
833     /**
834      * @see org.kuali.rice.krad.uif.view.ViewModel#isUpdateViewRequest()
835      */
836     @Override
837     public boolean isUpdateViewRequest() {
838         return isAjaxRequest() &&
839                 StringUtils.isNotBlank(getAjaxReturnType()) &&
840                 (isUpdateComponentRequest() || getAjaxReturnType().equals(
841                         UifConstants.AjaxReturnTypes.DISPLAYLIGHTBOX.getKey()));
842     }
843 
844     /**
845      * @see org.kuali.rice.krad.uif.view.ViewModel#setAjaxReturnType(java.lang.String)
846      */
847     @Override
848     public void setAjaxReturnType(String ajaxReturnType) {
849         this.ajaxReturnType = ajaxReturnType;
850     }
851 
852     /**
853      * Returns the String entered by the user when presented a dialog
854      *
855      * <p>
856      * Field defined here so all forms will be able to bind to a dialog using the same property
857      * </p>
858      *
859      * @return String - the text entered by a user as a reply in a modal dialog.
860      */
861     public String getDialogExplanation() {
862         return dialogExplanation;
863     }
864 
865     /**
866      * Sets the dialogExplanation text value.
867      *
868      * @param dialogExplanation - text entered by user when replying to a modal dialog
869      */
870     public void setDialogExplanation(String dialogExplanation) {
871         this.dialogExplanation = dialogExplanation;
872     }
873 
874     /**
875      * Represents the option chosen by the user when interacting with a modal dialog
876      *
877      * <p>
878      * This is used to determine which option was chosen by the user. The value is the key in the key/value pair
879      * selected in the control.
880      * </p>
881      *
882      * @return - String key selected by the user
883      */
884     public String getDialogResponse() {
885         return dialogResponse;
886     }
887 
888     /**
889      * Sets the response key text selected by the user as a response to a modal dialog
890      *
891      * @param dialogResponse - the key of the option chosen by the user
892      */
893     public void setDialogResponse(String dialogResponse) {
894         this.dialogResponse = dialogResponse;
895     }
896 
897     /**
898      * Gets the DialogManager for this view/form
899      *
900      * <p>
901      * The DialogManager tracks modal dialog interactions with the user
902      * </p>
903      *
904      * @return
905      */
906     public DialogManager getDialogManager() {
907         return dialogManager;
908     }
909 
910     /**
911      * Sets the DialogManager for this view
912      *
913      * @param dialogManager - DialogManager instance for this view
914      */
915     public void setDialogManager(DialogManager dialogManager) {
916         this.dialogManager = dialogManager;
917     }
918 
919     /**
920      * @see org.kuali.rice.krad.uif.view.ViewModel#getExtensionData()
921      */
922     public Map<String, Object> getExtensionData() {
923         return extensionData;
924     }
925 
926     /**
927      * @see org.kuali.rice.krad.uif.view.ViewModel#setExtensionData(java.util.Map<java.lang.String,java.lang.Object>)
928      */
929     public void setExtensionData(Map<String, Object> extensionData) {
930         this.extensionData = extensionData;
931     }
932 
933     /**
934      * The {@code List} that contains all newly added items for the collections on the model
935      *
936      * <p>
937      * This list contains the new items for all the collections on the model.
938      * </p>
939      *
940      * @return List of the newly added item lists
941      */
942     public List getAddedCollectionItems() {
943         return addedCollectionItems;
944     }
945 
946     /**
947      * Setter for the newly added item list
948      *
949      * @param addedCollectionItems
950      */
951     public void setAddedCollectionItems(List addedCollectionItems) {
952         this.addedCollectionItems = addedCollectionItems;
953     }
954 
955     /**
956      * Indicates whether an collection item has been newly added
957      *
958      * <p>
959      * Tests collection items against the list of newly added items on the model. This list gets cleared when the view
960      * is submitted and the items are persisted.
961      * </p>
962      *
963      * @param item - the item to test against list of newly added items
964      * @return boolean true if the item has been newly added
965      */
966     public boolean isAddedCollectionItem(Object item) {
967         return addedCollectionItems.contains(item);
968     }
969 
970 }