1

In earlier wicket versions, making a checkbox required ensured that it has to be checked by the user, or else it would fail validation. This is no longer the case in wicket 6. Is there a standard way to achieve the same behavior now?

1 Answers1

5

This is the relevant discussion on the topic:

http://apache-wicket.1842946.n4.nabble.com/quot-required-quot-for-Checkbox-td1854806.html

So you will have to use a validator on your checkbox:

public class TrueValidator implements IValidator<Boolean> {
    private static final long serialVersionUID = 1L;

    @Override
    public void validate(IValidatable<Boolean> validatable) {
        if (!Boolean.TRUE.equals(validatable.getValue())) {
            validatable.error(new ValidationError(this));
        }
    }
}
svenmeier
  • 5,681
  • 17
  • 22
  • 1
    Should this be added as a convenience in CheckBox#setRequired() ? If 'true' then add the validator, else remove it. – martin-g Mar 21 '15 at 13:20
  • So this means there's no standard built-in way to do it? Ok then. – aditsu quit because SE is EVIL Mar 25 '15 at 00:35
  • @martin-g That would kind of revert to the old behavior, right? If that's desired (which I really doubt), then an easier way would be to stop overriding checkRequired. I think a better approach is to provide something like TrueValidator above, as part of wicket, and let people add it manually when they want to. – aditsu quit because SE is EVIL Mar 25 '15 at 00:39