Class CaretPreservingOnChangeBehavior

java.lang.Object
org.apache.wicket.behavior.Behavior
org.apache.wicket.behavior.AbstractAjaxBehavior
org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
org.apache.wicket.ajax.AjaxEventBehavior
org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior
org.apache.wicket.ajax.form.OnChangeAjaxBehavior
com.evolveum.midpoint.web.component.behavior.CaretPreservingOnChangeBehavior
All Implemented Interfaces:
Serializable, org.apache.wicket.IComponentAwareEventSink, org.apache.wicket.IRequestListener, org.apache.wicket.markup.html.IComponentAwareHeaderContributor, org.apache.wicket.util.io.IClusterable

public class CaretPreservingOnChangeBehavior extends org.apache.wicket.ajax.form.OnChangeAjaxBehavior
An OnChangeAjaxBehavior that preserves the text caret position across AJAX updates for input components.

Useful for components where maintaining cursor location improves user experience during dynamic updates.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final Duration
    Debounce for instant single-click components (checkboxes).
    protected static final Duration
    For responsive selection inputs (dropdowns, radios).
    protected static final Duration
    For typing-based inputs (text fields, text areas).

    Fields inherited from class org.apache.wicket.ajax.form.OnChangeAjaxBehavior

    EVENT_CHANGE, EVENT_NAME

    Fields inherited from class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior

    INDICATOR
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected org.apache.wicket.Component
    Returns the component affected by the caret preservation logic.
    protected Duration
    Determines debounce interval dynamically based on component type.
    protected void
    onCaretAwareUpdate(@NotNull org.apache.wicket.ajax.AjaxRequestTarget target)
    Performs the actual component update during the AJAX callback.
    protected void
    onUpdate(org.apache.wicket.ajax.AjaxRequestTarget target)
    Restores the caret position after the component is refreshed by AJAX.
    protected void
    updateAjaxAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes attributes)
    Adds client-side logic to capture caret position before the AJAX call.

    Methods inherited from class org.apache.wicket.ajax.form.OnChangeAjaxBehavior

    onChange

    Methods inherited from class org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior

    checkComponent, disableFocusOnBlur, getFormComponent, getUpdateModel, onBind, onError, onEvent, onUpdate

    Methods inherited from class org.apache.wicket.ajax.AjaxEventBehavior

    getEvent, onEvent, renderHead, respond

    Methods inherited from class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior

    findIndicatorId, getAttributes, getCallbackFunction, getCallbackFunctionBody, getCallbackScript, getCallbackScript, onMethodMismatch, onRequest, postprocessConfiguration, renderAjaxAttributes, renderAjaxAttributes

    Methods inherited from class org.apache.wicket.behavior.AbstractAjaxBehavior

    afterRender, bind, getCallbackUrl, getComponent, onComponentRendered, onComponentTag, onComponentTag, onUnbind, unbind

    Methods inherited from class org.apache.wicket.behavior.Behavior

    beforeRender, canCallListener, detach, getStatelessHint, isEnabled, isTemporary, onAttribute, onConfigure, onEvent, onException, onRemove, onTag

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.apache.wicket.IRequestListener

    rendersPage
  • Field Details

    • INSTANT_DEBOUNCE

      protected static final Duration INSTANT_DEBOUNCE
      Debounce for instant single-click components (checkboxes).
    • RESPONSIVE_DEBOUNCE

      protected static final Duration RESPONSIVE_DEBOUNCE
      For responsive selection inputs (dropdowns, radios).
    • TYPING_DEBOUNCE

      protected static final Duration TYPING_DEBOUNCE
      For typing-based inputs (text fields, text areas).
  • Constructor Details

    • CaretPreservingOnChangeBehavior

      public CaretPreservingOnChangeBehavior()
  • Method Details

    • updateAjaxAttributes

      protected void updateAjaxAttributes(org.apache.wicket.ajax.attributes.AjaxRequestAttributes attributes)
      Adds client-side logic to capture caret position before the AJAX call. Injects JavaScript parameters representing the selection start and end indices.
      Overrides:
      updateAjaxAttributes in class org.apache.wicket.ajax.form.OnChangeAjaxBehavior
    • onUpdate

      protected void onUpdate(org.apache.wicket.ajax.AjaxRequestTarget target)
      Restores the caret position after the component is refreshed by AJAX. Also invokes onCaretAwareUpdate(AjaxRequestTarget) for additional updates.
      Specified by:
      onUpdate in class org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior
    • onCaretAwareUpdate

      protected void onCaretAwareUpdate(@NotNull @NotNull org.apache.wicket.ajax.AjaxRequestTarget target)
      Performs the actual component update during the AJAX callback. Subclasses may override to extend update behavior.
    • getAffectedComponent

      protected org.apache.wicket.Component getAffectedComponent()
      Returns the component affected by the caret preservation logic. Default implementation returns AbstractAjaxBehavior.getComponent().
    • getDebounceInterval

      protected Duration getDebounceInterval()
      Determines debounce interval dynamically based on component type.

      - CheckBox: INSTANT_DEBOUNCE
      - DropDownChoice: RESPONSIVE_DEBOUNCE
      - Other (e.g. text fields): TYPING_DEBOUNCE