Class EntityViewElementUtils

java.lang.Object
com.foreach.across.modules.entity.views.util.EntityViewElementUtils

public final class EntityViewElementUtils extends Object
Contains utility methods related to view elements and view building in an entity context.
Author:
Arne Vandamme
  • Method Details

    • currentEntity

      public static Object currentEntity(com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext)

      Retrieve the current entity being processed in the builder context. In case of a IteratorViewElementBuilderContext the entity of the iterator will be returned, in all other cases the attribute EntityViewModel.ENTITY.

      Will return null if no entity can be found.

      Parameters:
      builderContext - current builder context
      Returns:
      entity or null if none found
    • controlNamePostProcessor

      public static <T extends com.foreach.across.modules.web.ui.ViewElement> com.foreach.across.modules.web.ui.ViewElementPostProcessor<T> controlNamePostProcessor(@NonNull @NonNull EntityPropertyDescriptor descriptor)
      Create a ViewElementPostProcessor that generates the EntityPropertyControlName for the given property descriptor and sets it using FormInputElement.setControlName(String) on the generated control. This will update all FormInputElement elements where the current control name is the same asĀ EntityPropertyDescriptor.getName().

      Any container will be searched for FormInputElement children that might get updated as well.

      Type Parameters:
      T - form control element type
      Parameters:
      descriptor - property descriptor
      Returns:
      post processor
    • controlName

      public static EntityPropertyControlName controlName(@NonNull @NonNull EntityPropertyDescriptor descriptor, @NonNull @NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext)
      Generate the right EntityPropertyControlName for the property represented by the descriptor. Inspect the ViewElementBuilderContext and use a parent EntityPropertyControlName that might be set.

      The control name returned will be scoped to the EntityPropertyHandlingType resolved for the descriptor.

      Parameters:
      descriptor - for the property
      builderContext - that might contain a parent EntityPropertyControlName
      Returns:
      control name
      See Also:
    • currentEntity

      public static <U> U currentEntity(@NonNull @NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext, @NonNull @NonNull Class<U> expectedType)

      Retrieve the current entity being processed in the builder context. In case of a IteratorViewElementBuilderContext the entity of the iterator will be returned, in all other cases the attribute EntityViewModel.ENTITY.

      Will return null if no entity can be found or if the entity is not of the expected type.

      Parameters:
      builderContext - current builder context
      Returns:
      entity or null if none found or not of the expected type
    • currentPropertyValue

      public static Object currentPropertyValue(@NonNull @NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext)
      Retrieve the current property value being rendered. This assumes that an EntityPropertyDescriptor attribute is set on the context, and that currentEntity(ViewElementBuilderContext) returns a non-null value. If both conditions are true, the EntityPropertyDescriptor.getValueFetcher() will be used to retrieve the actual property value of the entity.

      Null will be returned if either entity or property descriptor are missing. However, null will also be returned if no value fetcher is configured or if the actual property value is null.

      Parameters:
      builderContext - current builder context
      Returns:
      property value or null if unable to determine
      See Also:
    • currentPropertyValue

      public static <U> U currentPropertyValue(@NonNull @NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext, @NonNull @NonNull Class<U> expectedType)
      Retrieve the current property value being rendered, if it is of the expected type. Depending on the type of property, this will fetch the property directly from the entity, or from the EntityPropertiesBinder that is present on the ViewElementBuilderContext.
      Type Parameters:
      U - property value type indicator
      Parameters:
      builderContext - current builder context
      expectedType - the property value should have
      Returns:
      property value or null if unable to determine or not of the expected type
      See Also:
    • currentPropertyBinder

      public static EntityPropertyBinder currentPropertyBinder(@NonNull @NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext)
      Retrieve a EntityPropertyBinder for the current property being rendered. This requires an EntityPropertiesBinder or a EntityPropertyBinder for the parent property to be present.
      Parameters:
      builderContext - current builder context
      Returns:
      binder for the property
    • currentPropertyDescriptor

      public static EntityPropertyDescriptor currentPropertyDescriptor(@NonNull @NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext)
      Retrieve the current property descriptor, if there is one. This looks for the EntityPropertyDescriptor attribute on the context.
      Parameters:
      builderContext - current builder context
      Returns:
      descriptor or null if not present
      See Also:
    • setCurrentEntity

      public static void setCurrentEntity(@NonNull @NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext, Object value)
      Set the current entity to the value specified.
    • setCurrentPropertyValue

      public static void setCurrentPropertyValue(@NonNull @NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext, Object value)
      Set a fixed EntityPropertyValue on the builder context. Care should be taken when using this approach as a property value set this way will take precedence over all other mechanisms. If a parent context contains a fixed property value, it will be used by all child contexts.

      Especially useful for test scenarios.

      Parameters:
      builderContext - on which to set the property value
      value - for the property