Custom validator for a SelectMany component
I did not succeed at validating a selectManyCheckBox with a custom validator.
I want to validate that the user selected at least 1 and at most 3 checkboxes.
The UIComponent.getSelectedValues always returns an array of length 0, even when some boxes are checked.
Page code:
<h:selectManyCheckbox id="selectProfessions" value="#{userBackingBean.selectedProfessionIDs}" layout="pageDirection" styleClass="category">
<f:selectItems value="#{categoryTreeBackingBean.professionSelectItems}" />
<f:validator validatorId="com.studio184.news.ui.validator.SelectCategoriesValidator"/>
</h:selectManyCheckbox>
Validate method:
UISelectMany select = (UISelectMany)component;
if (select.getSelectedValues() == null || select.getSelectedValues().length < 1 || select.getSelectedValues().length > 3) {
String summary = ...
String detail = ...
FacesMessage message = new FacesMessage(summary, detail);
message.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(message);
}
Any help would be greatly appreciated.
Bruno
http://www.practicalsoftwarearchitect.com

