Class EntityViewElementUtils
java.lang.Object
com.foreach.across.modules.entity.views.util.EntityViewElementUtils
Contains utility methods related to view elements and view building in an entity context.
- Author:
- Arne Vandamme
-
Method Summary
Modifier and TypeMethodDescriptionstatic EntityPropertyControlName
controlName
(@NonNull EntityPropertyDescriptor descriptor, @NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext) Generate the rightEntityPropertyControlName
for the property represented by the descriptor.static <T extends com.foreach.across.modules.web.ui.ViewElement>
com.foreach.across.modules.web.ui.ViewElementPostProcessor<T>controlNamePostProcessor
(@NonNull EntityPropertyDescriptor descriptor) Create aViewElementPostProcessor
that generates theEntityPropertyControlName
for the given property descriptor and sets it usingFormInputElement.setControlName(String)
on the generated control.static <U> U
currentEntity
(@NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext, @NonNull Class<U> expectedType) Retrieve the current entity being processed in the builder context.static Object
currentEntity
(com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext) Retrieve the current entity being processed in the builder context.static EntityPropertyBinder
currentPropertyBinder
(@NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext) Retrieve aEntityPropertyBinder
for the current property being rendered.static EntityPropertyDescriptor
currentPropertyDescriptor
(@NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext) Retrieve the current property descriptor, if there is one.static Object
currentPropertyValue
(@NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext) Retrieve the current property value being rendered.static <U> U
currentPropertyValue
(@NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext, @NonNull Class<U> expectedType) Retrieve the current property value being rendered, if it is of the expected type.static void
setCurrentEntity
(@NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext, Object value) Set the current entity to the value specified.static void
setCurrentPropertyValue
(@NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext, Object value) Set a fixedEntityPropertyValue
on the builder context.
-
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 attributeEntityViewModel.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 aViewElementPostProcessor
that generates theEntityPropertyControlName
for the given property descriptor and sets it usingFormInputElement.setControlName(String)
on the generated control. This will update allFormInputElement
elements where the current control name is the same asĀEntityPropertyDescriptor.getName()
. Any container will be searched forFormInputElement
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 rightEntityPropertyControlName
for the property represented by the descriptor. Inspect theViewElementBuilderContext
and use a parentEntityPropertyControlName
that might be set. The control name returned will be scoped to theEntityPropertyHandlingType
resolved for the descriptor.- Parameters:
descriptor
- for the propertybuilderContext
- that might contain a parentEntityPropertyControlName
- 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 attributeEntityViewModel.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 anEntityPropertyDescriptor
attribute is set on the context, and thatcurrentEntity(ViewElementBuilderContext)
returns a non-null value. If both conditions are true, theEntityPropertyDescriptor.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 theEntityPropertiesBinder
that is present on theViewElementBuilderContext
.- Type Parameters:
U
- property value type indicator- Parameters:
builderContext
- current builder contextexpectedType
- 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 aEntityPropertyBinder
for the current property being rendered. This requires anEntityPropertiesBinder
or aEntityPropertyBinder
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 theEntityPropertyDescriptor
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 fixedEntityPropertyValue
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 valuevalue
- for the property
-