Class ControlNamePrefixAdjuster<T extends com.foreach.across.modules.web.ui.ViewElement>
java.lang.Object
com.foreach.across.modules.bootstrapui.utils.ControlNamePrefixAdjuster<T>
- All Implemented Interfaces:
com.foreach.across.modules.web.ui.ViewElementPostProcessor<T>
,Consumer<T>
public class ControlNamePrefixAdjuster<T extends com.foreach.across.modules.web.ui.ViewElement>
extends Object
implements Consumer<T>, com.foreach.across.modules.web.ui.ViewElementPostProcessor<T>
Helper class for updating the control name of an
FormInputElement
.
Will update the element control name and (depending on the value of recurse(boolean)
, will also update all
child controls if the element is a container.
A new instance is pre-configured for bean style element control names: dotted separators will be added and any control
name starting with an underscore is modified *after* the underscore.
When processing the container members, this prefixer ensures that controls are only modified a single time,
and ensures correct handling of FormControlElement.Proxy
controls.
This is an implementation of both Consumer<com.foreach.across.modules.web.ui.ViewElement>
and ViewElementPostProcessor
so it can easily
be passed around and used in different contexts.- Since:
- 2.1.0
- Author:
- Arne Vandamme
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(com.foreach.across.modules.web.ui.ViewElement element) controlNamePredicate
(Predicate<String> controlNamePredicate) An additional custom predicate that the (unmodified) control name should match before it is modified.elementPredicate
(Predicate<FormInputElement> elementPredicate) Additional predicate that the candidates should match before they are modified.ignoreUnderscore
(boolean ignoreUnderscore) Set tofalse
if you want to treat any control name starting with an underscore as an exact control name.insertDotSeparator
(boolean insertDotSeparator) Set tofalse
if you want to apply the new prefixToAdd as is.void
postProcess
(com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext, com.foreach.across.modules.web.ui.ViewElement element) prefixToAdd
(@NonNull String prefixToAdd) The new prefixToAdd that should be set on the control name.prefixToReplace
(String prefixToReplace) Prefix value that should be replaced.recurse
(boolean recurse) Set tofalse
if you only want to apply the name modification to the initial element, and not recurse through the child elements if the element is a container.
-
Constructor Details
-
ControlNamePrefixAdjuster
public ControlNamePrefixAdjuster()
-
-
Method Details
-
postProcess
public void postProcess(com.foreach.across.modules.web.ui.ViewElementBuilderContext builderContext, com.foreach.across.modules.web.ui.ViewElement element) - Specified by:
postProcess
in interfacecom.foreach.across.modules.web.ui.ViewElementPostProcessor<T extends com.foreach.across.modules.web.ui.ViewElement>
-
accept
public void accept(com.foreach.across.modules.web.ui.ViewElement element) -
prefixToReplace
Prefix value that should be replaced. When specified, only controls matching the prefixToAdd will be modified. If not specified, all control names will be prefixed.- Returns:
this
.
-
prefixToAdd
The new prefixToAdd that should be set on the control name.- Returns:
this
.
-
insertDotSeparator
Set tofalse
if you want to apply the new prefixToAdd as is. Whentrue
(default), a dot will be inserted between the new prefixToAdd and the remaining segment if the remaning segment does not start with a dot or an indexer related character ({,[ or ().- Returns:
this
.
-
recurse
Set tofalse
if you only want to apply the name modification to the initial element, and not recurse through the child elements if the element is a container. When false and the initial element is not aFormInputElement
, nothing will happen.- Returns:
this
.
-
ignoreUnderscore
Set tofalse
if you want to treat any control name starting with an underscore as an exact control name. If not, a starting _ will be ignored for the control name predicate and prefixing will be done after the _. A control starting with underscore is usually a special element for Spring data-binding.- Returns:
this
.
-
elementPredicate
Additional predicate that the candidates should match before they are modified. Recursing through members of a candidate will happen regardless of the predicate.- Returns:
this
.
-
controlNamePredicate
An additional custom predicate that the (unmodified) control name should match before it is modified.- Returns:
this
.
-