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
FieldsModifier and TypeFieldDescriptionprotected static final DurationDebounce for instant single-click components (checkboxes).protected static final DurationFor responsive selection inputs (dropdowns, radios).protected static final DurationFor typing-based inputs (text fields, text areas).Fields inherited from class org.apache.wicket.ajax.form.OnChangeAjaxBehavior
EVENT_CHANGE, EVENT_NAMEFields inherited from class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
INDICATOR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected org.apache.wicket.ComponentReturns the component affected by the caret preservation logic.protected DurationDetermines debounce interval dynamically based on component type.protected voidonCaretAwareUpdate(@NotNull org.apache.wicket.ajax.AjaxRequestTarget target) Performs the actual component update during the AJAX callback.protected voidonUpdate(org.apache.wicket.ajax.AjaxRequestTarget target) Restores the caret position after the component is refreshed by AJAX.protected voidupdateAjaxAttributes(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
onChangeMethods inherited from class org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior
checkComponent, disableFocusOnBlur, getFormComponent, getUpdateModel, onBind, onError, onEvent, onUpdateMethods inherited from class org.apache.wicket.ajax.AjaxEventBehavior
getEvent, onEvent, renderHead, respondMethods inherited from class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
findIndicatorId, getAttributes, getCallbackFunction, getCallbackFunctionBody, getCallbackScript, getCallbackScript, onMethodMismatch, onRequest, postprocessConfiguration, renderAjaxAttributes, renderAjaxAttributesMethods inherited from class org.apache.wicket.behavior.AbstractAjaxBehavior
afterRender, bind, getCallbackUrl, getComponent, onComponentRendered, onComponentTag, onComponentTag, onUnbind, unbindMethods inherited from class org.apache.wicket.behavior.Behavior
beforeRender, canCallListener, detach, getStatelessHint, isEnabled, isTemporary, onAttribute, onConfigure, onEvent, onException, onRemove, onTagMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.wicket.IRequestListener
rendersPage
-
Field Details
-
INSTANT_DEBOUNCE
Debounce for instant single-click components (checkboxes). -
RESPONSIVE_DEBOUNCE
For responsive selection inputs (dropdowns, radios). -
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:
updateAjaxAttributesin classorg.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 invokesonCaretAwareUpdate(AjaxRequestTarget)for additional updates.- Specified by:
onUpdatein classorg.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 returnsAbstractAjaxBehavior.getComponent(). -
getDebounceInterval
Determines debounce interval dynamically based on component type.-
CheckBox:INSTANT_DEBOUNCE
-DropDownChoice:RESPONSIVE_DEBOUNCE
- Other (e.g. text fields):TYPING_DEBOUNCE
-