In a similar case I've used a wrapper around validators which controls
whether they run or not. This way you can automatically parse the form
component tree, find all validators and wrap them in a new Validator that
runs them only if needed.

I've done this because I wanted to be able to have the standard wicket
validators run in onValidateModelObjects(). I.e. I wanted my model to be
updated even if some validations did not pass.

So here's the basic idea (this is slightly modified from my actual code so
it may have small errors).

public abstract class ValidatorWrapper<T> implements IValidator<T> {
        IValidator<T> validator;
 public DelayedValidator(IValidator<T> validator) {
super();
this.validator = validator;
}

        protected abstract boolean shouldRun();

@Override
public void validate(IValidatable<T> validatable) {
if (!shouldRun())
return;
if (validatable.getValue() == null) {
if (!(validator instanceof INullAcceptingValidator<?>)) {
return;
}
}
validator.validate(validatable);
}
}

It is reasonably easy to extend this for FormValidators as well.

This does not handle the case of conversion errors, i.e. in an Integer
TextField if the user input is not a valid integer, it won't update the
model object. So if you auto-save and the reload, such fields will be
empty. This is something that would actually be a lot of work to handle
because you would need a custom model that would actually store string
values.

Cheers
Marios


On Tue, Jan 7, 2014 at 9:32 PM, gmparker2000 <greg.par...@brovada.com>wrote:

> Interesting but unfortunately our form is very complex with repeaters, etc.
> So I don't think this would work for us.
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Auto-save-feature-tp4663517p4663522.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

Reply via email to