There is a situation when the AjaxFormComponentUpdatingBehavior
deafult functionality fails. When we want to attach this behavior (or
OnChangeAjaxBehavior) to reflect changes inside a Model of
FormComponent which is marked as REQUIRED event if user clears
component input. In such situation AjaxFormComponentUpdatingBehavior
calls validation, FormComponent is not valid so error message is
reported and Model is not updated (I want to update this Model beacuse
the other things on form may depend on it).
My proposition is to extend this behavior to handle such use-cases
when user clears FormComponent input:
1. Do not update a Model and report error message (current and the
default behavior).
2. Update a Model and not report any error messages.
3. Update a Model and report error message.
It can be done by adding to boolean properties to this behavior (they
both be null by default) - feel free to invent a better names ;):
- disabledValidation
- alwaysUpdateModel
The change in code (not tested yet :)):
protected final void onEvent(final AjaxRequestTarget target)
{
final FormComponent<?> formComponent = getFormComponent();
if (getEvent().toLowerCase().equals("onblur") &&
disableFocusOnBlur())
{
target.focusComponent(null);
}
try
{
formComponent.inputChanged();
if (!isDisabledValidation) {
formComponent.validate();
}
if (formComponent.hasErrorMessage())
{
formComponent.invalid();
if (isAlwaysUpdateModel()) {
if (getUpdateModel())
{
formComponent.updateModel();
}
}
onError(target, null);
}
else
{
formComponent.valid();
if (getUpdateModel())
{
formComponent.updateModel();
}
onUpdate(target);
}
}
catch (RuntimeException e)
{
onError(target, e);
}
}
--
Daniel
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]