How to require ticking a checkbox in wicket 6?

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?

Upvotes: 1

Views: 1001

Answers (1)

svenmeier
svenmeier

Reputation: 5681

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));
        }
    }
}

Upvotes: 5

Related Questions