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