I created a small validator and would like to share it with you all.
If there is already something like that, I will appreciate if someone direct
me to it.
This is a From Validator.
If you have several checkboxes in a form and you want that *at least* one
checkbox to be selected, you can use this validator.

Here is the code:

public class CheckboxesSelectValidator extends AbstractFormValidator {

    private static final long serialVersionUID = -5475763159946590330L;
    /** form components to be checked. */
    private final CheckBox[] components;
    private final String optionsMessage;

    public CheckboxesSelectValidator(CheckBox[] components, String
optionsMessage) {
        this.components = components;
        this.optionsMessage = optionsMessage;

    public FormComponent[] getDependentFormComponents() {
        return components;

     * At least one check box should be checked
    public void validate(Form form) {
        for (CheckBox component : components) {
            if (((Boolean) component.getConvertedInput()).booleanValue()) {

    protected Map variablesMap() {
        Map args = new HashMap(1);
        args.put("options", optionsMessage);
        return args;

Here is a sample usage:
                new CheckboxesSelectValidator(new CheckBox[] {
                        modelconfCheckbox },

And this is the error message (taken from the properties file):

CheckboxesSelectValidator = Please select at least one option from

Any remarks will be appreciated as well.

Eyal Golan

Visit: http://jvdrums.sourceforge.net/
LinkedIn: http://www.linkedin.com/in/egolan74

P  Save a tree. Please don't print this e-mail unless it's really necessary

Reply via email to