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 EntityPropertyControlNamecontrolName(@NonNull EntityPropertyDescriptor descriptor, @NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext) Generate the rightEntityPropertyControlNamefor 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 aViewElementPostProcessorthat generates theEntityPropertyControlNamefor the given property descriptor and sets it usingFormInputElement.setControlName(String)on the generated control.static <U> UcurrentEntity(@NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext, @NonNull Class<U> expectedType) Retrieve the current entity being processed in the builder context.static ObjectcurrentEntity(com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext) Retrieve the current entity being processed in the builder context.static EntityPropertyBindercurrentPropertyBinder(@NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext) Retrieve aEntityPropertyBinderfor the current property being rendered.static EntityPropertyDescriptorcurrentPropertyDescriptor(@NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext) Retrieve the current property descriptor, if there is one.static ObjectcurrentPropertyValue(@NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext) Retrieve the current property value being rendered.static <U> UcurrentPropertyValue(@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 voidsetCurrentEntity(@NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext, Object value) Set the current entity to the value specified.static voidsetCurrentPropertyValue(@NonNull com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext, Object value) Set a fixedEntityPropertyValueon 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
IteratorViewElementBuilderContextthe 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 aViewElementPostProcessorthat generates theEntityPropertyControlNamefor the given property descriptor and sets it usingFormInputElement.setControlName(String)on the generated control. This will update allFormInputElementelements where the current control name is the same asĀEntityPropertyDescriptor.getName(). Any container will be searched forFormInputElementchildren 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 rightEntityPropertyControlNamefor the property represented by the descriptor. Inspect theViewElementBuilderContextand use a parentEntityPropertyControlNamethat might be set. The control name returned will be scoped to theEntityPropertyHandlingTyperesolved 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
IteratorViewElementBuilderContextthe 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 anEntityPropertyDescriptorattribute 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 theEntityPropertiesBinderthat 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 aEntityPropertyBinderfor the current property being rendered. This requires anEntityPropertiesBinderor aEntityPropertyBinderfor 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 theEntityPropertyDescriptorattribute 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 fixedEntityPropertyValueon 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
-