Class ViewHelperServiceImpl

java.lang.Object
org.kuali.rice.krad.uif.service.impl.ViewHelperServiceImpl
All Implemented Interfaces:
Serializable, ViewHelperService
Direct Known Subclasses:
DocumentViewHelperServiceImpl, InquirableImpl, LookupableImpl, MaintainableImpl

public class ViewHelperServiceImpl extends Object implements ViewHelperService, Serializable
Default Implementation of ViewHelperService
Author:
Kuali Rice Team (rice.collab@kuali.org)
See Also:
  • Constructor Details

    • ViewHelperServiceImpl

      public ViewHelperServiceImpl()
  • Method Details

    • addCustomContainerComponents

      public void addCustomContainerComponents(ViewModel model, Container container)
      Hook for creating new components with code and adding them to a container

      Subclasses can override this method to check for one or more containers by id and then adding components created in code. This is invoked before the initialize method on the container component, so the full lifecycle will be run on the components returned.

      New components instances can be retrieved using ComponentFactory

      Specified by:
      addCustomContainerComponents in interface ViewHelperService
      Parameters:
      model - object containing the view data
      container - container instance to add components to
    • buildInquiryLink

      public void buildInquiryLink(Object dataObject, String propertyName, Inquiry inquiry)
      Finds the Inquirable configured for the given data object class and delegates to it for building the inquiry URL Invoked by the Inquiry widget to build the inquiry link

      Note this is used primarily for custom Inquirable implementations to customize the inquiry class or parameters for an inquiry. Instead of building the full inquiry link, implementations can make a callback to org.kuali.rice.krad.uif.widget.Inquiry.buildInquiryLink(Object, String, Classinvalid input: '<'?>, Mapinvalid input: '<'String, String>) given an inquiry class and parameters to build the link field.

      Specified by:
      buildInquiryLink in interface ViewHelperService
      Parameters:
      dataObject - parent object for the inquiry property
      propertyName - name of the property the inquiry is being built for
      inquiry - instance of the inquiry widget being built for the property
    • performCustomApplyModel

      public void performCustomApplyModel(LifecycleElement element, Object model)
      Hook for service overrides to perform custom apply model logic on the component
      Specified by:
      performCustomApplyModel in interface ViewHelperService
      Parameters:
      element - component instance to apply model to
      model - Top level object containing the data (could be the model or a top level business object, dto)
    • performCustomFinalize

      public void performCustomFinalize(LifecycleElement element, Object model, LifecycleElement parent)
      Hook for service overrides to perform custom component finalization
      Specified by:
      performCustomFinalize in interface ViewHelperService
      Parameters:
      element - component instance to update
      model - Top level object containing the data
      parent - Parent component for the component being finalized
    • performCustomInitialization

      public void performCustomInitialization(LifecycleElement element)
      Hook for service overrides to perform custom initialization on the component
      Specified by:
      performCustomInitialization in interface ViewHelperService
      Parameters:
      element - component instance to initialize
    • performCustomViewFinalize

      public void performCustomViewFinalize(Object model)
      Hook for service overrides to perform view component finalization
      Specified by:
      performCustomViewFinalize in interface ViewHelperService
      Parameters:
      model - Top level object containing the data
    • performCustomViewInitialization

      public void performCustomViewInitialization(Object model)
      Hook for service overrides to perform custom initialization prior to view initialization.
      Specified by:
      performCustomViewInitialization in interface ViewHelperService
      Parameters:
      model - The model.
    • processAfterAddLine

      public void processAfterAddLine(ViewModel model, Object lineObject, String collectionId, String collectionPath, boolean isValidLine)
      Hook for service overrides to process the new collection line after it has been added to the collection
      Specified by:
      processAfterAddLine in interface ViewHelperService
      Parameters:
      model - object instance that contain's the views data
      lineObject - the new line that was added
      collectionId - the id of the collection being added to
      collectionPath - the path to the collection being modified
      isValidLine - indicates if the line is valid
    • processAfterDeleteLine

      public void processAfterDeleteLine(ViewModel model, String collectionId, String collectionPath, int lineIndex)
      Hook for service overrides to process the collection line after it has been deleted
      Specified by:
      processAfterDeleteLine in interface ViewHelperService
      Parameters:
      model - object instance that contains the views data
      collectionId - the id of the collection being added to
      collectionPath - the path to the collection being modified
      lineIndex - index of the line that was deleted
    • processAfterSaveLine

      public void processAfterSaveLine(ViewModel model, Object lineObject, String collectionId, String collectionPath)
      Hook for service overrides to process the save collection line after it has been validated
      Specified by:
      processAfterSaveLine in interface ViewHelperService
      Parameters:
      model - object instance that contains the views data
      lineObject - the line instance to be processed
      collectionId - the id of the collection being added to
      collectionPath - the path to the collection being modified
    • processBeforeAddLine

      public void processBeforeAddLine(ViewModel model, Object addLine, String collectionId, String collectionPath)
      Hook for service overrides to process the new collection line before it is added to the collection
      Specified by:
      processBeforeAddLine in interface ViewHelperService
      Parameters:
      model - object instance that contain's the view's data
      addLine - the new line instance to be processed
      collectionId - the id of the collection being added to
      collectionPath - the path to the collection being modified
    • processBeforeSaveLine

      public void processBeforeSaveLine(ViewModel model, Object lineObject, String collectionId, String collectionPath)
      Hook for service overrides to process the save collection line before it is validated
      Specified by:
      processBeforeSaveLine in interface ViewHelperService
      Parameters:
      model - object instance that contain's the views data
      lineObject - the line instance to be processed
      collectionId - the id of the collection being added to
      collectionPath - the path to the collection being modified
    • processBeforeEditLine

      public void processBeforeEditLine(ViewModel model, Object lineObject, String collectionId, String collectionPath)
      Hook for service overrides to process the edit collection line before it is validated
      Specified by:
      processBeforeEditLine in interface ViewHelperService
      Parameters:
      model - object instance that contain's the views data
      lineObject - the line instance to be processed
      collectionId - the id of the collection being edited from
      collectionPath - the path to the collection being modified
    • processAfterEditLine

      public void processAfterEditLine(ViewModel model, Object lineObject, String collectionId, String collectionPath)
      Hook for service overrides to process the edit collection line after it has been validated
      Specified by:
      processAfterEditLine in interface ViewHelperService
      Parameters:
      model - object instance that contains the views data
      lineObject - the line instance to be processed
      collectionId - the id of the collection being edited from
      collectionPath - the path to the collection being modified
    • processCollectionAddBlankLine

      public void processCollectionAddBlankLine(ViewModel model, String collectionId, String collectionPath)
      Adds a blank line to the collection

      Adds a new collection item to the collection and applies any default values.

      Specified by:
      processCollectionAddBlankLine in interface ViewHelperService
      Parameters:
      model - Top level object containing the view data including the collection and new line
      collectionId - the id of the collection being added to
      collectionPath - the path to the collection being modified
    • processCollectionAddLine

      public void processCollectionAddLine(ViewModel model, String collectionId, String collectionPath)
      Invoked when the add line action is chosen for a collection. The collection path gives the full path to the collection that action was selected for. Here validation can be performed on the line as well as further processing on the line such as defaults. If the action is valid the line should be added to the collection, otherwise errors should be added to the global MessageMap
      Specified by:
      processCollectionAddLine in interface ViewHelperService
      Parameters:
      model - Top level object containing the view data including the collection and new line
      collectionId - the id of the collection being added to
      collectionPath - the path to the collection being modified
    • processAndAddLineObject

      public void processAndAddLineObject(ViewModel viewModel, Object newLine, String collectionId, String collectionPath)
      Do all processing related to adding a line: calls processBeforeAddLine, performAddLineValidation, addLine, processAfterAddLine
      Specified by:
      processAndAddLineObject in interface ViewHelperService
      Parameters:
      viewModel - object instance that contain's the view's data
      newLine - the new line instance to be processed
      collectionId - the id of the collection being added to
      collectionPath - the path to the collection being modified
    • processCollectionDeleteLine

      public void processCollectionDeleteLine(ViewModel model, String collectionId, String collectionPath, int lineIndex)
      Invoked when the delete line action is chosen for a collection. The collection path gives the full path to the collection that action was selected for. Here validation can be performed to make sure the action is allowed. If the action is valid the line should be deleted from the collection, otherwise errors should be added to the global MessageMap
      Specified by:
      processCollectionDeleteLine in interface ViewHelperService
      Parameters:
      model - Top level object containing the view data including the collection
      collectionId - the id of the collection being added to
      collectionPath - the path to the collection being modified
      lineIndex - index of the collection line that was selected for removal
    • processCollectionRetrieveEditLineDialog

      public void processCollectionRetrieveEditLineDialog(ViewModel model, String collectionId, String collectionPath, int selectedLineIndex)
      Invoked when the retrieve edit line dialog action is chosen for a collection. This method only does server side validation by default but creates hook for client applications to add additional logic like persisting data.
      Specified by:
      processCollectionRetrieveEditLineDialog in interface ViewHelperService
      Parameters:
      model - Top level object containing the view data including the collection and new line
      collectionId - the id of the collection being added to
      collectionPath - the path to the collection being modified
      selectedLineIndex - The index within the collection of the line to edit.
    • processCollectionEditLine

      public void processCollectionEditLine(ViewModel model, CollectionControllerServiceImpl.CollectionActionParameters parameterData)
      Invoked when the edit line action is chosen for a collection. This method only does server side validation by default but creates hook for client applications to add additional logic like persisting data.
      Specified by:
      processCollectionEditLine in interface ViewHelperService
      Parameters:
      model - Top level object containing the view data including the collection and new line
      parameterData - the parameters for edit line request
    • processCollectionCloseEditLineDialog

      public void processCollectionCloseEditLineDialog(ViewModel model, String collectionId, String collectionPath, int selectedLineIndex)
      Invoked when the close edit line dialog action is chosen for a collection.
      Specified by:
      processCollectionCloseEditLineDialog in interface ViewHelperService
      Parameters:
      model - Top level object containing the view data including the collection and new line
      collectionId - the id of the collection being added to
      collectionPath - the path to the collection being modified
      selectedLineIndex - The index within the collection of the line to edit.
    • processCollectionSaveLine

      public void processCollectionSaveLine(ViewModel model, CollectionControllerServiceImpl.CollectionActionParameters parameterData)
      Invoked when the save line action is chosen for a collection. This method only does server side validation by default but creates hook for client applications to add additional logic like persisting data.
      Specified by:
      processCollectionSaveLine in interface ViewHelperService
      Parameters:
      model - Top level object containing the view data including the collection and new line
      parameterData - the parameters for save line request
    • extractNewValuesAndAssign

      protected Object extractNewValuesAndAssign(String collectionPath, int selectedLineIndex, Map<String,String[]> parameters, List<Object> collection)
      Gets the current object from the collection and assigns the new values to it.
      Parameters:
      collectionPath - the path to the collection being modified
      selectedLineIndex - The index within the collection of the line to save.
      parameters - the path to the collection being modified
      collection - the collection of the lines of data
      Returns:
      true if the action is allowed and the line should be removed, false if the line should not be removed
    • extractSingleValue

      protected String extractSingleValue(String[] data)
      Extract a single value form an array of strings
      Parameters:
      data - the array of strings
    • processMultipleValueLookupResults

      public void processMultipleValueLookupResults(ViewModel model, String collectionId, String collectionPath, String multiValueReturnFields, String lookupResultValues)
      Process the results returned from a multi-value lookup populating the lines for the collection given by the path
      Specified by:
      processMultipleValueLookupResults in interface ViewHelperService
      Parameters:
      model - object containing the view data
      collectionId - the id of the collection being added to
      collectionPath - the path to the collection being modified
      multiValueReturnFields - String containing the selected line field names
      lookupResultValues - String containing the selected line values
    • addLine

      protected int addLine(Collection<Object> collection, Object addLine, boolean insertFirst)
      Add addLine to collection while giving derived classes an opportunity to override for things like sorting.
      Parameters:
      collection - the Collection to add the given addLine to
      addLine - the line to add to the given collection
      insertFirst - indicates if the item should be inserted as the first item
      Returns:
      the index at which the item was added to the collection, or -1 if it was not added
    • linkAddedLine

      protected boolean linkAddedLine(Object model, String collectionPath, int addedIndex)
      Set the parent for bi-directional relationships when adding a line to a collection.
      Parameters:
      model - the view data
      collectionPath - the path to the collection being linked
      addedIndex - the index of the added line
      Returns:
      whether the linked line needs further processing
    • performAddLineValidation

      protected boolean performAddLineValidation(ViewModel viewModel, Object newLine, String collectionId, String collectionPath)
      Performs validation on the new collection line before it is added to the corresponding collection.
      Parameters:
      viewModel - object instance that contain's the view's data
      newLine - the new line instance to be processed
      collectionId - the id of the collection being added to
      collectionPath - the path to the collection being modified
    • filterByReturnedFieldConversions

      protected Map<String,String> filterByReturnedFieldConversions(String multiValueReturnFields, Map<String,String> fieldConversions)
      Filters the field conversions by the multi value return fields
      Parameters:
      multiValueReturnFields - the return fields to filter by, as a comma separated string
      fieldConversions - the map of field conversions to filter
      Returns:
      a Map containing the filtered field conversions
    • containsDuplicateLine

      protected boolean containsDuplicateLine(Object addLine, Collection<Object> collectionItems, List<String> duplicateLinePropertyNames)
      Determines whether the new line matches one of the entries in the existing collection, based on the duplicateLinePropertyNames.
      Parameters:
      addLine - new line instance to validate
      collectionItems - items in the collection
      duplicateLinePropertyNames - property names to check for duplicates
      Returns:
      true if there is a duplicate line, false otherwise
    • isDuplicateLine

      protected boolean isDuplicateLine(Object addLine, Object collectionItem, List<String> duplicateLinePropertyNames)
      Determines whether the new addLine is a duplicate of collectionItem, based on the duplicateLinePropertyNames.
      Parameters:
      addLine - new line instance to validate
      collectionItem - existing instance to validate
      duplicateLinePropertyNames - the property names to check for duplicates
      Returns:
      true if addLine is a duplicate of collectionItem, false otherwise
    • performDeleteLineValidation

      protected boolean performDeleteLineValidation(ViewModel model, String collectionId, String collectionPath, Object deleteLine)
      Performs validation on the collection line before it is removed from the corresponding collection.
      Parameters:
      model - object instance that contain's the view's data
      collectionId - the id of the collection being added to
      collectionPath - the path to the collection being modified
      deleteLine - line that will be removed
      Returns:
      true if the action is allowed and the line should be removed, false if the line should not be removed
    • applyDefaultValuesForCollectionLine

      public void applyDefaultValuesForCollectionLine(CollectionGroup collectionGroup, Object line)
      Populate default values the model backing a line in a collection group.
      Specified by:
      applyDefaultValuesForCollectionLine in interface ViewHelperService
      Parameters:
      collectionGroup - The collection group.
      line - The model object backing the line.
    • applyDefaultValues

      public void applyDefaultValues(Component component)
      Iterates through the view components picking up data fields and applying an default value configured
      Specified by:
      applyDefaultValues in interface ViewHelperService
      Parameters:
      component - component that should be checked for default values
    • populateViewFromRequestParameters

      public void populateViewFromRequestParameters(Map<String,String> parameters)
      Uses reflection to find all fields defined on the View instance that have the RequestParameter annotation (which indicates the field may be populated by the request).

      The View instance is inspected for fields that have the RequestParameter annotation and if corresponding parameters are found in the request parameter map, the request value is used to set the view property. The Map of parameter name/values that match are placed in the view so they can be later retrieved to rebuild the view. Custom ViewServiceHelper implementations can add additional parameter key/value pairs to the returned map if necessary.

      For each field found, if there is a corresponding key/value pair in the request parameters, the value is used to populate the field. In addition, any conditional properties of PropertyReplacers configured for the field are cleared so that the request parameter value does not get overridden by the dictionary conditional logic

      Specified by:
      populateViewFromRequestParameters in interface ViewHelperService
      Parameters:
      parameters - The request parameters that apply to the view.
      See Also:
    • buildGrowlScript

      public String buildGrowlScript()
      Builds JS script that will invoke the show growl method to display a growl message when the page is rendered

      A growl call will be created for any explicit growl messages added to the message map.

      Growls are only generated if @{link org.kuali.rice.krad.uif.view.View#isGrowlMessagingEnabled()} is enabled. If not, the growl messages are set as info messages for the page

      Specified by:
      buildGrowlScript in interface ViewHelperService
      Returns:
      JS script string for generated growl messages
    • populateDefaultValueForField

      public void populateDefaultValueForField(Object object, DataField dataField, String bindingPath)
      Applies the default value configured for the given field (if any) to the line given object property that is determined by the given binding path
      Specified by:
      populateDefaultValueForField in interface ViewHelperService
      Parameters:
      object - object that should be populated
      dataField - field to check for configured default value
      bindingPath - path to the property on the object that should be populated
    • getDefaultValueForField

      public Object getDefaultValueForField(Object object, DataField dataField)
      Retrieves the default value that is configured for the given data field

      The field's default value is determined in the following order:

      1. If default value on field is non-blank
      2. If expression is found for default value
      3. If default value finder class is configured for field
      4. If an expression is found for default values
      5. If default values on field is not null
      Specified by:
      getDefaultValueForField in interface ViewHelperService
      Parameters:
      object - object that should be populated
      dataField - field to retrieve default value for
      Returns:
      Object default value for field or null if value was not found
    • refreshReference

      public void refreshReference(Object parentObject, String referenceObjectName)
      Perform a database or data dictionary based refresh of a specific property object

      The object needs to be of type PersistableBusinessObject.

      Specified by:
      refreshReference in interface ViewHelperService
      Parameters:
      parentObject - parent object that references the object to be refreshed
      referenceObjectName - property name of the parent object to be refreshed
    • refreshReferences

      public void refreshReferences(String referencesToRefresh)
      Update the reference objects listed in referencesToRefresh of the model

      The the individual references in the referencesToRefresh string are separated by KRADConstants.REFERENCES_TO_REFRESH_SEPARATOR).

      Specified by:
      refreshReferences in interface ViewHelperService
      Parameters:
      referencesToRefresh - list of references to refresh (
    • retrieveEditModesAndActionFlags

      public void retrieveEditModesAndActionFlags()
      Invokes the configured PresentationController and Authorizer for the view to get the exported action flags and edit modes that can be used in conditional logic
      Specified by:
      retrieveEditModesAndActionFlags in interface ViewHelperService
    • setViewContext

      public void setViewContext()
      Sets up the view context which will be available to other components through their context for conditional logic evaluation.
      Specified by:
      setViewContext in interface ViewHelperService
    • setElementContext

      public void setElementContext(LifecycleElement element, LifecycleElement parent)
      Invoked to set up the context for an element.

      Context is primarily used for expression evaluation. Any object in the context for a component will be available as a variable within expressions.

      Specified by:
      setElementContext in interface ViewHelperService
      Parameters:
      element - element to setup context for
      parent - parent of the given element
    • getCurrentPersonContactId

      public String getCurrentPersonContactId()
    • getConfigurationService

      protected org.kuali.rice.core.api.config.property.ConfigurationService getConfigurationService()
      Gets the configuration service
      Returns:
      configuration service
    • setConfigurationService

      public void setConfigurationService(org.kuali.rice.core.api.config.property.ConfigurationService configurationService)
      Sets the configuration service
      Parameters:
      configurationService - The configuration service.
    • getDataDictionaryService

      protected DataDictionaryService getDataDictionaryService()
      Gets the data dictionary service
      Returns:
      data dictionary service
    • setDataDictionaryService

      public void setDataDictionaryService(DataDictionaryService dataDictionaryService)
      Sets the data dictionary service
      Parameters:
      dataDictionaryService - The dictionary service.
    • getViewDictionaryService

      protected ViewDictionaryService getViewDictionaryService()
      Gets the view dictionary service
      Returns:
      view dictionary service
    • setViewDictionaryService

      public void setViewDictionaryService(ViewDictionaryService viewDictionaryService)
      Sets the view dictionary service
      Parameters:
      viewDictionaryService - The view dictionary service.
    • getExpressionEvaluatorFactory

      public ExpressionEvaluatorFactory getExpressionEvaluatorFactory()
      Gets an expression evaluator factory for use with the current view.
      Specified by:
      getExpressionEvaluatorFactory in interface ViewHelperService
      Returns:
      expression evaluator factory
    • setExpressionEvaluatorFactory

      public void setExpressionEvaluatorFactory(ExpressionEvaluatorFactory expressionEvaluatorFactory)
      Parameters:
      expressionEvaluatorFactory - expression evaluator factory
    • getLegacyDataAdapter

      protected LegacyDataAdapter getLegacyDataAdapter()
      Get the legacy data adapter.
      Returns:
      The legacy data adapter.
    • getDataObjectService

      protected org.kuali.rice.krad.data.DataObjectService getDataObjectService()
    • setDataObjectService

      protected void setDataObjectService(org.kuali.rice.krad.data.DataObjectService dataObjectService)
    • setLegacyDataAdapter

      public void setLegacyDataAdapter(LegacyDataAdapter legacyDataAdapter)
      Set the legacy data adapter.
      Parameters:
      legacyDataAdapter - The legacy data adapter.
    • logAndThrowRuntime

      protected void logAndThrowRuntime(String message)
      Log an error message using log4j, then throw a runtime exception with the provided message.
      Parameters:
      message - The error message.