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 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 interface com.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)
      Specified by:
      accept in interface Consumer<T extends com.foreach.across.modules.web.ui.ViewElement>
    • prefixToReplace

      public ControlNamePrefixAdjuster<T> prefixToReplace(String 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

      public ControlNamePrefixAdjuster<T> prefixToAdd(@NonNull @NonNull String prefixToAdd)
      The new prefixToAdd that should be set on the control name.
      Returns:
      this.
    • insertDotSeparator

      public ControlNamePrefixAdjuster<T> insertDotSeparator(boolean insertDotSeparator)
      Set to false if you want to apply the new prefixToAdd as is. When true (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

      public ControlNamePrefixAdjuster<T> recurse(boolean recurse)
      Set to false 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 a FormInputElement, nothing will happen.

      Returns:
      this.
    • ignoreUnderscore

      public ControlNamePrefixAdjuster<T> ignoreUnderscore(boolean ignoreUnderscore)
      Set to false 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

      public ControlNamePrefixAdjuster<T> elementPredicate(Predicate<FormInputElement> 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

      public ControlNamePrefixAdjuster<T> controlNamePredicate(Predicate<String> controlNamePredicate)
      An additional custom predicate that the (unmodified) control name should match before it is modified.
      Returns:
      this.