Package org.apache.wicket.ajax.form
Class AjaxFormComponentUpdatingBehavior
- 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
-
- All Implemented Interfaces:
java.io.Serializable,IComponentAwareEventSink,IRequestListener,IComponentAwareHeaderContributor,org.apache.wicket.util.io.IClusterable
- Direct Known Subclasses:
AjaxFormChoiceComponentUpdatingBehavior,OnChangeAjaxBehavior
public abstract class AjaxFormComponentUpdatingBehavior extends AjaxEventBehavior
A behavior that updates the hosting FormComponent via ajax when an event it is attached to is triggered. This behavior encapsulates the entire form-processing workflow as relevant only to this component so if validation is successful the component's model will be updated according to the submitted value.NOTE: This behavior does not validate any
IFormValidators attached to this form even though they may reference the component being updated.NOTE: This behavior does not work on Choices or Groups use the
AjaxFormChoiceComponentUpdatingBehaviorfor that.- Since:
- 1.2
- Author:
- Igor Vaynberg (ivaynberg)
- See Also:
onUpdate(org.apache.wicket.ajax.AjaxRequestTarget),onError(org.apache.wicket.ajax.AjaxRequestTarget, RuntimeException), Serialized Form
-
-
Field Summary
-
Fields inherited from class org.apache.wicket.ajax.AbstractDefaultAjaxBehavior
INDICATOR
-
-
Constructor Summary
Constructors Constructor Description AjaxFormComponentUpdatingBehavior(java.lang.String event)Construct.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidcheckComponent(FormComponent<?> component)Check the component this behavior is bound to.protected booleandisableFocusOnBlur()Determines whether the focus will not be restored when the event is blur.protected FormComponent<?>getFormComponent()protected booleangetUpdateModel()Gives the control to the application to decide whether the form component model should be updated automatically or not.protected voidonBind()Subclasses should call super.onBind()protected voidonError(AjaxRequestTarget target, java.lang.RuntimeException e)Called to handle any error resulting from updating form component.protected voidonEvent(AjaxRequestTarget target)Listener method for the ajax eventstatic AjaxFormComponentUpdatingBehavioronUpdate(java.lang.String eventName, org.danekja.java.util.function.serializable.SerializableConsumer<AjaxRequestTarget> onUpdate)Creates anAjaxFormComponentUpdatingBehaviorbased on lambda expressionsprotected abstract voidonUpdate(AjaxRequestTarget target)Listener invoked on the ajax request.protected voidupdateAjaxAttributes(AjaxRequestAttributes attributes)Gives a chance to the specializations to modify the attributes.-
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, 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
-
-
-
-
Method Detail
-
onBind
protected void onBind()
Description copied from class:AbstractDefaultAjaxBehaviorSubclasses should call super.onBind()- Overrides:
onBindin classAbstractDefaultAjaxBehavior- See Also:
AbstractAjaxBehavior.onBind()
-
checkComponent
protected void checkComponent(FormComponent<?> component)
Check the component this behavior is bound to.Logs a warning in development mode when an
AjaxFormChoiceComponentUpdatingBehaviorshould be used.- Parameters:
component- bound component
-
getFormComponent
protected final FormComponent<?> getFormComponent()
- Returns:
- FormComponent
-
updateAjaxAttributes
protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
Description copied from class:AbstractDefaultAjaxBehaviorGives a chance to the specializations to modify the attributes.- Overrides:
updateAjaxAttributesin classAjaxEventBehavior
-
onEvent
protected final void onEvent(AjaxRequestTarget target)
Description copied from class:AjaxEventBehaviorListener method for the ajax event- Specified by:
onEventin classAjaxEventBehavior- Parameters:
target- the current request handler- See Also:
AjaxEventBehavior.onEvent(org.apache.wicket.ajax.AjaxRequestTarget)
-
getUpdateModel
protected boolean getUpdateModel()
Gives the control to the application to decide whether the form component model should be updated automatically or not. Make sure to callFormComponent.valid()additionally in case the application want to update the model manually.- Returns:
- true if the model of form component should be updated, false otherwise
-
disableFocusOnBlur
protected boolean disableFocusOnBlur()
Determines whether the focus will not be restored when the event is blur. By default this is true, as we don't want to re-focus component on blur event.- Returns:
trueif refocusing should be disabled,falseotherwise
-
onUpdate
protected abstract void onUpdate(AjaxRequestTarget target)
Listener invoked on the ajax request. This listener is invoked after the component's model has been updated.Note:
onError(AjaxRequestTarget, RuntimeException)is called instead when processing of theFormComponentfailed with conversion or validation errors!- Parameters:
target- the current request handler
-
onError
protected void onError(AjaxRequestTarget target, java.lang.RuntimeException e)
Called to handle any error resulting from updating form component. Errors thrown fromonUpdate(org.apache.wicket.ajax.AjaxRequestTarget)will not be caught here. The RuntimeException will be null if it was just a validation or conversion error of the FormComponent- Parameters:
target- the current request handlere- the error that occurred during the update of the component
-
onUpdate
public static AjaxFormComponentUpdatingBehavior onUpdate(java.lang.String eventName, org.danekja.java.util.function.serializable.SerializableConsumer<AjaxRequestTarget> onUpdate)
Creates anAjaxFormComponentUpdatingBehaviorbased on lambda expressions- Parameters:
eventName- the event nameonUpdate- theSerializableConsumerwhich accepts theAjaxRequestTarget- Returns:
- the
AjaxFormComponentUpdatingBehavior
-
-