Class EntityViewCommand

java.lang.Object
com.foreach.across.modules.entity.views.request.EntityViewCommand

public class EntityViewCommand extends Object
Represents an entity view command object. In case of a form view will usually hold the DTO of the entity being created or updated. Additionally extension objects can be registered that will be bound and validated as well.

Apart from the extension data itself, a list of custom validators for that extension can be added.

This is the central object exchanged between the view and allows for form-binding.

Since:
2.0.0
Author:
Arne Vandamme
  • Constructor Details

    • EntityViewCommand

      public EntityViewCommand()
  • Method Details

    • setEntity

      public void setEntity(Object entity)
    • getEntity

      public Object getEntity()
      Returns:
      The entity (dto) instance for the command.
    • getEntity

      public <V> V getEntity(Class<V> entityType)
      Returns:
      the entity cast as type
    • getExtensions

      public Map<String,Object> getExtensions()
      Returns:
      Map of possible command extensions that have been registered.
    • addExtensionWithValidator

      public void addExtensionWithValidator(String extensionName, Object extension, org.springframework.validation.Validator... validators)
      Shorthand for adding an extension with custom validators.
      Parameters:
      extensionName - name of the extension
      extension - object
      validators - for the extension
    • addExtension

      public void addExtension(String name, Object extension)
      Add an extension object under the given key. Will replace any previously registered extension.
      Parameters:
      name - of the extension object
      extension - object - data binding will also happen on this extension as well as validation if default binding occurs
    • addExtensionValidator

      public void addExtensionValidator(String extensionName, org.springframework.validation.Validator... validators)
      Add one or more custom validators for an extension.
      Parameters:
      extensionName - name of the extension
      validators - to add
    • getExtension

      public <Y> Y getExtension(String extensionName)
      Return the extension with the given name and coerce it to the expected type.
      Type Parameters:
      Y - type of the extension object
      Parameters:
      extensionName - name of the extension
      Returns:
      extension value
    • getExtension

      public <Y> Y getExtension(String extensionName, Class<Y> extensionType)
      Return the extension with the given name and coerce it to the expected type.
      Type Parameters:
      Y - type of the extension object
      Parameters:
      extensionName - name of the extension
      extensionType - type of the extension object
      Returns:
      extension value
    • getExtensionValidators

      public Collection<org.springframework.validation.Validator> getExtensionValidators(String extensionName)
      Get the collections of additional Validator instances that should be applied when validating the extension data.
      Parameters:
      extensionName - name of the extension
      Returns:
      collection of validators
    • holdsEntity

      public boolean holdsEntity()
      Returns:
      true if an entity is set on this command
    • hasExtension

      public boolean hasExtension(String extensionName)
      Check if an extension was registered under the given name. Note that the extension value can be null.
      Parameters:
      extensionName - name of the extension
      Returns:
      true if extension was registered
    • removeExtension

      public void removeExtension(String extensionName)
      Remove the extension with that name. This will also remove the validators for that extension.
      Parameters:
      extensionName - name of the extension
    • getProperties

      public EntityPropertiesBinder getProperties()
      A binder object for custom property binding through EntityPropertyController.
    • setProperties

      public void setProperties(EntityPropertiesBinder properties)
      A binder object for custom property binding through EntityPropertyController.