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.uif.view;
17  
18  import org.kuali.rice.krad.uif.UifConstants.ViewType;
19  
20  import javax.servlet.http.HttpServletRequest;
21  import java.io.Serializable;
22  import java.util.List;
23  import java.util.Map;
24  import java.util.Set;
25  
26  /**
27   * Interface that must be implemented for classes the provide the backing data (model) for a {@link View}
28   *
29   * <p>
30   * Since the View relies on helper properties from the model it is necessary the backing object implement the
31   * ViewModel interface. Note model objects can extend {@link org.kuali.rice.krad.web.form.UifFormBase} which implements
32   * the ViewModel interface.
33   * </p>
34   *
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   */
37  public interface ViewModel extends Serializable {
38  
39      /**
40       * Called after Spring binds the request to the form and before the controller method is invoked
41       *
42       * @param request - request object containing the query parameters
43       */
44      public void postBind(HttpServletRequest request);
45  
46      /**
47       * Unique Id for the <code>View</code> instance. This is specified for a
48       * view in its definition by setting the 'id' property.
49       *
50       * @return String view id
51       */
52      public String getViewId();
53  
54      /**
55       * Setter for the unique view id
56       *
57       * @param viewId
58       */
59      public void setViewId(String viewId);
60  
61      /**
62       * Name for the <code>View</code> instance. This is specified for a view in
63       * its definition by setting the 'id' property. The name is not necessary
64       * unique and cannot be used by itself to retrieve a view. Typically it is
65       * used with other parameters to identify a view with a certain type (view
66       * type)
67       *
68       * @return String view name
69       */
70      public String getViewName();
71  
72      /**
73       * Setter for the view name
74       *
75       * @param viewName
76       */
77      public void setViewName(String viewName);
78  
79      /**
80       * Name for the type of view being requested. This can be used to find
81       * <code>View</code> instances by request parameters (not necessary the
82       * unique id)
83       *
84       * @return String view type name
85       */
86      public ViewType getViewTypeName();
87  
88      /**
89       * Setter for the view type name
90       *
91       * @param viewTypeName
92       */
93      public void setViewTypeName(ViewType viewTypeName);
94  
95      /**
96       * View instance associated with the model. Used to render the user interface
97       *
98       * @return View
99       */
100     public View getView();
101 
102     /**
103      * Setter for the view instance
104      *
105      * @param view
106      */
107     public void setView(View view);
108 
109     /**
110      * View instance for the page that made a request. Since a new view instance
111      * gets initialized for each request before the controller logic is invoked,
112      * any state about the previous view is lost. This could be needed to read
113      * metadata from the view for such things as collection processing. When
114      * this is necessary the previous view instance can be retrieved
115      *
116      * @return View instance
117      */
118     public View getPostedView();
119 
120     /**
121      * Setter for the previous view instance
122      *
123      * @param previousView
124      */
125     public void setPostedView(View previousView);
126 
127     /**
128      * Id for the current page being displayed within the view
129      *
130      * @return String page id
131      */
132     public String getPageId();
133 
134     /**
135      * Setter for the current page id
136      *
137      * @param pageId
138      */
139     public void setPageId(String pageId);
140 
141     /**
142      * URL the form generated for the view should post to
143      *
144      * @return String form post URL
145      */
146     public String getFormPostUrl();
147 
148     /**
149      * Setter for the form post URL
150      *
151      * @param formPostUrl
152      */
153     public void setFormPostUrl(String formPostUrl);
154 
155     /**
156      * Map of parameters that was used to configured the <code>View</code>.
157      * Maintained on the form to rebuild the view on posts and session timeout
158      *
159      * @return Map<String, String> view parameters
160      * @see org.kuali.rice.krad.uif.view.View.getViewRequestParameters()
161      */
162     public Map<String, String> getViewRequestParameters();
163 
164     /**
165      * Setter for the view's request parameter map
166      *
167      * @param viewRequestParameters
168      */
169     public void setViewRequestParameters(Map<String, String> viewRequestParameters);
170 
171     /**
172      * List of fields that should be read only on the view
173      *
174      * <p>
175      * If the view being rendered supports request setting of read-only fields, the readOnlyFields request parameter
176      * can be sent to mark fields as read only that might not have been otherwise
177      * </p>
178      *
179      * <p>
180      * Note the paths specified should be the simple property names (not the full binding path). Therefore if the
181      * property name appears multiple times in the view, all instances will be set as read only
182      * </p>
183      *
184      * @return List<String> read only property names
185      * @see View#isSupportsRequestOverrideOfReadOnlyFields()
186      */
187     public List<String> getReadOnlyFieldsList();
188 
189     /**
190      * Setter for the list of read only fields
191      *
192      * @param readOnlyFieldsList
193      */
194     public void setReadOnlyFieldsList(List<String> readOnlyFieldsList);
195 
196     /**
197      * Holds instances for collection add lines. The key of the Map gives the
198      * collection name the line instance applies to, the Map value is an
199      * instance of the collection object class that holds the new line data
200      *
201      * @return Map<String, Object> new collection lines
202      */
203     public Map<String, Object> getNewCollectionLines();
204 
205     /**
206      * Setter for the new collection lines Map
207      *
208      * @param newCollectionLines
209      */
210     public void setNewCollectionLines(Map<String, Object> newCollectionLines);
211 
212     /**
213      * Map of parameters sent for the invoked action
214      *
215      * <p>
216      * Many times besides just setting the method to call actions need to send
217      * additional parameters. For instance the method being called might do a
218      * redirect, in which case the action needs to send parameters for the
219      * redirect URL. An example of this is redirecting to a <code>Lookup</code>
220      * view. In some cases the parameters that need to be sent conflict with
221      * properties already on the form, and putting all the action parameters as
222      * form properties would grow massive (in addition to adds an additional
223      * step from the XML config). So this general map solves those issues.
224      * </p>
225      *
226      * @return Map<String, String> action parameters
227      */
228     public Map<String, String> getActionParameters();
229 
230     /**
231      * Setter for the action parameters map
232      *
233      * @param actionParameters
234      */
235     public void setActionParameters(Map<String, String> actionParameters);
236 
237     /**
238      * Map that is populated from the component state maintained on the client
239      *
240      * <p>
241      * Used when a request is made that refreshes part of the view. The current state for components (which
242      * have state that can be changed on the client), is populated into this map which is then used by the
243      * <code>ViewHelperService</code> to update the components so that the state is maintained when they render.
244      * </p>
245      *
246      * @return Map<String, Object> map where key is name of property or component id, and value is the property
247      *         value or another map of component key/value pairs
248      */
249     public Map<String, Object> getClientStateForSyncing();
250 
251     /**
252      * Holds Set of String identifiers for lines that were selected in a collection
253      *
254      * <p>
255      * When the select field is enabled for a <code>CollectionGroup</code>, the framework will be
256      * default bind the selected identifier strings to this property. The key of the map uniquely identifies the
257      * collection by the full binding path to the collection, and the value is a set of Strings for the checked
258      * lines.
259      * </p>
260      *
261      * @return Map<String, Set<String>> map of collections and their selected lines
262      * @see org.kuali.rice.krad.service.LegacyDataAdapter#getDataObjectIdentifierString(java.lang.Object)
263      */
264     public Map<String, Set<String>> getSelectedCollectionLines();
265 
266     /**
267      * Setter for the map that holds selected collection lines
268      *
269      * @param selectedCollectionLines
270      */
271     public void setSelectedCollectionLines(Map<String, Set<String>> selectedCollectionLines);
272 
273     /**
274      * Indicates whether the form has had default values from the configured
275      * <code>View</code> applied. This happens only once for each form instance
276      *
277      * @return boolean true if default values have been applied, false if not
278      */
279     public boolean isDefaultsApplied();
280 
281     /**
282      * Setter for the defaults applied indicator
283      *
284      * @param defaultsApplied
285      */
286     public void setDefaultsApplied(boolean defaultsApplied);
287 
288     /**
289      * Script that will run on render (view or component) for generating growl messages
290      *
291      * @return String JS growl script
292      */
293     public String getGrowlScript();
294 
295     /**
296      * Setter for the script that generates growls on render
297      *
298      * @param growlScript
299      */
300     public void setGrowlScript(String growlScript);
301 
302     /**
303      * Script that will run on render (view or component) for a lightbox
304      *
305      * @return String JS lightbox script
306      */
307     public String getLightboxScript();
308 
309     /**
310      * Setter for the script that generates a lightbox on render
311      *
312      * @param lightboxScript
313      */
314     public void setLightboxScript(String lightboxScript);
315 
316     /**
317      * Gets the state.  This is the default location for state on KRAD forms.
318      *
319      * @return the state
320      */
321     public String getState();
322 
323     /**
324      * Set the state
325      *
326      * @param state
327      */
328     public void setState(String state);
329 
330     /**
331      * Id for the component that should be updated for a component refresh process
332      *
333      * @return String component id
334      */
335     public String getUpdateComponentId();
336 
337     /**
338      * Setter for the component id that should be refreshed
339      *
340      * @param updateComponentId
341      */
342     public void setUpdateComponentId(String updateComponentId);
343 
344     /**
345      * Indicates whether the request was made by an ajax call
346      *
347      * <p>
348      * Depending on whether the request was made via ajax (versus standard browser submit) the response
349      * will be handled different. For example with an ajax request we can send back partial page updates, which
350      * cannot be done with standard submits
351      * </p>
352      *
353      * <p>
354      * If this indicator is true, {@link #getAjaxReturnType()} will be used to determine how to handling
355      * the ajax return
356      * </p>
357      *
358      * @return boolean true if the request was an ajax call, false if not
359      */
360     public boolean isAjaxRequest();
361 
362     /**
363      * Set the ajaxRequest
364      *
365      * @param ajaxRequest
366      */
367     public void setAjaxRequest(boolean ajaxRequest);
368 
369     /**
370      * Gets the return type for the ajax call
371      *
372      * <p>
373      * The ajax return type indicates how the response content will be handled in the client. Typical
374      * examples include updating a component, the page, or doing a redirect.
375      * </p>
376      *
377      * @return String return type
378      * @see org.kuali.rice.krad.uif.UifConstants.AjaxReturnTypes
379      */
380     public String getAjaxReturnType();
381 
382     /**
383      * Indicates whether the request is to update a component (only applicable for ajax requests)
384      *
385      * @return boolean true if the request is for update component, false if not
386      */
387     public boolean isUpdateComponentRequest();
388 
389     /**
390      * Indicates whether the request is to update a page (only applicable for ajax requests)
391      *
392      * @return boolean true if the request is for update page, false if not
393      */
394     public boolean isUpdatePageRequest();
395 
396     /**
397      * Indicates whether the request is to update a dialog (only applicable for ajax requests)
398      *
399      * @return boolean true if the request is for update dialog, false if not
400      */
401     public boolean isUpdateDialogRequest();
402 
403     /**
404      * Indicates whether the request is for a non-update of the view (only applicable for ajax requests)
405      *
406      * <p>
407      * Examples of requests that do not update the view are ajax queries or requests that download a file
408      * </p>
409      *
410      * @return boolean true if the request is for non-update, false if not
411      */
412     public boolean isUpdateNoneRequest();
413 
414     /**
415      * Indicates whether the request will result in building an entire view
416      *
417      * @return boolean true if the full view will be built, false if not
418      */
419     public boolean isBuildViewRequest();
420 
421     public boolean isUpdateViewRequest();
422 
423     /**
424      * Setter for the type of ajax return
425      *
426      * @param ajaxReturnType
427      */
428     public void setAjaxReturnType(String ajaxReturnType);
429 
430     /**
431      * Indicates whether the request should return a JSON string
432      *
433      * <p>
434      * When this indicator is true, the rendering process will invoke the template
435      * given by {@link #getRequestJsonTemplate()} which should return a JSON string
436      * </p>
437      *
438      * <p>
439      * For JSON requests the view is not built, however a component can be retrieved and
440      * exported in the request by setting {@link #getUpdateComponentId()}
441      * </p>
442      *
443      * @return boolean true if request is for JSON, false if not
444      */
445     public boolean isJsonRequest();
446 
447     /**
448      * Template the will be invoked to return a JSON string
449      *
450      * <p>
451      * Certain templates can be rendered to build JSON for a JSON request. The template
452      * set here (by a controller) will be rendered
453      * </p>
454      *
455      * @return path to template
456      */
457     public String getRequestJsonTemplate();
458 
459     /**
460      * Setter for the template to render for the request
461      *
462      * @param requestJsonTemplate
463      */
464     public void setRequestJsonTemplate(String requestJsonTemplate);
465 
466     /**
467      * A generic map for framework pieces (such as component modifiers) that need to dynamically store
468      * data to the form
469      *
470      * @return Map<String, Object>
471      */
472     public Map<String, Object> getExtensionData();
473 
474     /**
475      * Setter for the generic extension data map
476      *
477      * @param extensionData
478      */
479     public void setExtensionData(Map<String, Object> extensionData);
480 }