Class ViewLifecycle

java.lang.Object
org.kuali.rice.krad.uif.lifecycle.ViewLifecycle
All Implemented Interfaces:
Serializable

public class ViewLifecycle extends Object implements Serializable
Lifecycle object created during the view processing to hold event registrations.
Author:
Kuali Rice Team (rice.collab@kuali.org)
See Also:
  • Method Details

    • encapsulateLifecycle

      public static void encapsulateLifecycle(View view, Object model, javax.servlet.http.HttpServletRequest request, Runnable lifecycleProcess)
      Encapsulate a new view lifecycle process on the current thread.
      Parameters:
      view - The view to perform lifecycle processing on.
      model - The model associated with the view.
      request - The active servlet request.
      lifecycleProcess - The lifecycle process to encapsulate.
    • encapsulateLifecycle

      public static void encapsulateLifecycle(View view, Object model, ViewPostMetadata viewPostMetadata, ComponentPostMetadata refreshComponentPostMetadata, javax.servlet.http.HttpServletRequest request, Runnable lifecycleProcess)
      Encapsulate a new view lifecycle process on the current thread.
      Parameters:
      lifecycleProcess - The lifecycle process to encapsulate.
    • preProcess

      public static void preProcess(View view)
      Performs preliminary processing on a view, prior to caching.

      Logic evaluated at this preliminary phase result in global modifications to the view's subcomponents, so this method can be used apply additional logic to the View that is both pre-evaluated and shared by all instances of the component.

      Parameters:
      view - view to preprocess
    • buildView

      public static ViewPostMetadata buildView(View view, Object model, javax.servlet.http.HttpServletRequest request, Map<String,String> parameters)
      Executes the view lifecycle on the given View instance which will prepare it for rendering

      Any configuration sent through the options Map is used to initialize the View. This map contains present options the view is aware of and will typically come from request parameters. e.g. For maintenance Views there is the maintenance type option (new, edit, copy)

      After view retrieval, applies updates to the view based on the model data which Performs dynamic generation of fields (such as collection rows), conditional logic, and state updating (conditional hidden, read-only, required).

      Parameters:
      view - view instance that should be built
      model - object instance containing the view data
      request - The active servlet request.
      parameters - - Map of key values pairs that provide configuration for the View, this is generally comes from the request and can be the request parameter Map itself. Any parameters not valid for the View will be filtered out
    • performComponentLifecycle

      public static Component performComponentLifecycle(View view, Object model, javax.servlet.http.HttpServletRequest request, ViewPostMetadata viewPostMetadata, String componentId)
      Performs a lifecycle process to rebuild the component given by the update id.
      Parameters:
      view - view instance the component belongs to
      model - object containing the full view data
      request - The active servlet request.
      viewPostMetadata - post metadata for the view
      componentId - id of the component within the view, used to pull the current component from the view
      Returns:
      component instance the lifecycle has been run on
    • setupStandaloneComponentForRefresh

      protected static void setupStandaloneComponentForRefresh(View view, String componentId, ComponentPostMetadata componentPostMetadata)
      Before running the lifecycle on a component that is not attached to a view, we need to retrieve the component, add it to the dialogs list, and setup its refresh paths.
      Parameters:
      view - view instance the component should be attached to
      componentId - id for the component the lifecycle should be run on
      componentPostMetadata - post metadata instance for the component
    • isRefreshComponent

      public static boolean isRefreshComponent(String viewPhase, String viewPath)
      Indicates if the component the phase is being run on is a component being refreshed (if this is a full lifecycle this method will always return false).
      Returns:
      boolean true if the component is being refreshed, false if not
    • getRefreshComponentPhasePath

      public static String getRefreshComponentPhasePath(String viewPhase)
      When a refresh lifecycle is being processed, returns the phase path (path at the current phase) for the component being refreshed.
      Returns:
      path for refresh component at this phase, or null if this is not a refresh lifecycle
    • invokeEventListeners

      public void invokeEventListeners(ViewLifecycle.LifecycleEvent event, View view, Object model, LifecycleElement eventElement)
      Invoked when an event occurs to invoke registered listeners.
      Parameters:
      event - event that has occurred
      view - view instance the lifecycle is being executed for
      model - object containing the model data
      eventElement - component instance the event occurred on/for
      See Also:
    • registerLifecycleCompleteListener

      public void registerLifecycleCompleteListener(Component eventComponent, LifecycleEventListener listenerComponent)
      Registers the given component as a listener for the lifecycle complete event for the given event component.

      The ViewLifecycle.LifecycleEvent.LIFECYCLE_COMPLETE is thrown immediately after the finalize phase has been completed for a component. This can be useful if a component needs to set state after the lifecycle has been completed on another component (for example, it might depend on properties of that component that are set during the finalize phase of that component)

      Parameters:
      eventComponent - component the event will occur for
      listenerComponent - component to invoke when the event is thrown
      See Also:
    • isStrict

      public static boolean isStrict()
      Determines whether or not the lifecycle is operating in strict mode.

      LifecycleElement.getViewStatus() is checked at the beginning and end of each lifecycle phase. When operating in strict mode, when a component is in the wrong status for the current phase IllegalStateException will be thrown. When not in strict mode, warning messages are logged on the console.

      This value is controlled by the configuration parameter "krad.uif.lifecycle.strict". In Rice 2.4, the view lifecycle is *not* strict by default.

      Returns:
      true for strict operation, false to treat lifecycle violations as warnings
    • isRenderInLifecycle

      public static boolean isRenderInLifecycle()
      Determines whether or not to enable rendering within the lifecycle.

      This value is controlled by the configuration parameter "krad.uif.lifecycle.render".

      Returns:
      true for rendering within the lifecycle, false if all rendering should be deferred for Spring view processing
    • isAsynchronousLifecycle

      public static boolean isAsynchronousLifecycle()
      Determines whether or not to processing view lifecycle phases asynchronously.

      This value is controlled by the configuration parameter "krad.uif.lifecycle.asynchronous".

      Returns:
      true if view lifecycle phases should be performed asynchronously, false for synchronous operation
    • isTrace

      public static boolean isTrace()
      Determines whether or not to log trace details for troubleshooting lifecycle phases.

      View lifecycle tracing is very verbose. This feature should only be enabled for troubleshooting purposes.

      This value is controlled by the configuration parameter "krad.uif.lifecycle.trace".

      Returns:
      true if view lifecycle phase processing information should be logged
    • reportIllegalState

      public static void reportIllegalState(String message)
      Report an illegal state in the view lifecycle.

      When isStrict() returns true, IllegalStateException will be thrown. Otherwise, a warning will be logged.

      Parameters:
      message - The message describing the illegal state.
      Throws:
      IllegalStateException - If strict mode is enabled.
    • reportIllegalState

      public static void reportIllegalState(String message, Throwable cause)
      Report an illegal state in the view lifecycle.

      When isStrict() returns true, IllegalStateException will be thrown. Otherwise, a warning will be logged.

      Parameters:
      message - The message describing the illegal state.
      cause - The (potential) cause of the illegal state.
      Throws:
      IllegalStateException - If strict mode is enabled.
    • getHelper

      public static ViewHelperService getHelper()
      Gets the helper active within a lifecycle on the current thread.
      Returns:
      helper active on the current thread
    • getView

      public static View getView()
      Gets the view active within a lifecycle on the current thread.
      Returns:
      view active on the current thread
    • getExpressionEvaluator

      public static ExpressionEvaluator getExpressionEvaluator()
      Return an instance of ExpressionEvaluator that can be used for evaluating expressions contained on the view

      A ExpressionEvaluator must be initialized with a model for expression evaluation. One instance is constructed for the view lifecycle and made available to all components/helpers through this method

      Returns:
      instance of ExpressionEvaluator
    • getModel

      public static Object getModel()
      Gets the model related to the view active within this context.
      Returns:
      model related to the view active within this context
    • getVisitedIds

      public static Set<String> getVisitedIds()
      Gets the set of visited IDs for use during the apply model phase.
      Returns:
      The set of visited IDs for use during the apply model phase.
    • getViewPostMetadata

      public static ViewPostMetadata getViewPostMetadata()
      Returns the view post metadata instance associated with the view and lifecycle.
      Returns:
      view post metadata instance
    • getRefreshComponentPostMetadata

      public static ComponentPostMetadata getRefreshComponentPostMetadata()
      When the lifecycle is processing a component refresh, returns a ComponentPostMetadata instance for the component being refresh.
      Returns:
      post metadata for the component being refreshed
    • isRefreshLifecycle

      public static boolean isRefreshLifecycle()
      Indicates whether the lifecycle is processing a component refresh.
      Returns:
      boolean true if the lifecycle is refreshing a component, false for the full lifecycle
    • getRequest

      public static javax.servlet.http.HttpServletRequest getRequest()
      Gets the servlet request for this lifecycle.
      Returns:
      servlet request for this lifecycle
    • getPhase

      public static ViewLifecyclePhase getPhase()
      Gets the current phase of the active lifecycle, or null if no phase is currently active.
      Returns:
      current phase of the active lifecycle
    • getRenderingContext

      public static LifecycleRenderingContext getRenderingContext()
      Gets the rendering context for this lifecycle.
      Returns:
      rendering context for this lifecycle
    • getProcessor

      public static ViewLifecycleProcessor getProcessor()
      Gets the lifecycle processor active on the current thread.
      Returns:
      lifecycle processor active on the current thread
    • getActiveLifecycle

      public static ViewLifecycle getActiveLifecycle()
      Gets the view context active on the current thread.
      Returns:
      view context active on the current thread
    • isActive

      public static boolean isActive()
      Determine if a lifecycle processor is active on the current thread.
      Returns:
      True if a lifecycle processor is active on the current thread.
    • getRefreshComponentId

      public static String getRefreshComponentId()
      Id of the component to refresh.
    • setRefreshComponentId

      public static void setRefreshComponentId(String id)
      See Also: