I Daniel, how alwaysUpdateModel differs from updateModel? If you have an
required form component that support some clean up logic, it can be coded
inside AjaxFormComponentUpdatingBehavior#onError, and if you need an AJAX
behavior that don't validate the form component, you can
use AjaxEventBehavior instead of AjaxFormComponentUpdatingBehavior.
The code you sent will end up invoking formComponent.valid() for non valid
components, it is problematic.

On Thu, Feb 17, 2011 at 2:51 PM, Daniel Stoch <daniel.st...@gmail.com>wrote:

> 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: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


-- 
Pedro Henrique Oliveira dos Santos

Reply via email to