You need a custom Validator which throws a ValidatorException when the checkbox contains too many checked items. This Validator needs to be attached to the checkbox component and there should be a h:message or a h:messages component somewhere in the view which can display the validation error.
You need a custom Validator which throws a ValidatorException when the checkbox contains too many checked items. This Validator needs to be attached to the checkbox component and there should be a or a component somewhere in the view which can display the validation error. The ajax event is wrong.
Inside a dropdown, you would like to hook on the change event instead. Inside a checkbox or radio button you would like to hook on click event instead. Both which are already the default when you leave the event attribute to default.
Each component should in turn ajax-submit themselves and the other one and finally re-render the message component to reflect the validation error. In order to figure the selected dropdown value inside the custom validator, the cleanest way would be to set the whole dropdown component as a custom attribute of the checkbox component. This can be achieved by binding the dropdown to the view by binding attribute and specify that as value of inside the checkbox.
The dropdown component and thus also its value can then be obtained inside the custom validator. Summarized, the below kickoff example should work (note that I used as adds no extra advantages in this particular case and I admittedly can't tell from top of head how and if that would work): With @FacesValidator("myCheckboxValidator") public class MyCheckboxValidator implements Validator { @Override public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { UIInput chartTypeComponent = (UIInput) component.getAttributes(). Get("chartType"); String chartType = (String) chartTypeComponent.getValue(); List selectedItemscheckbox = (List) value; if ("PieChart".
Equals(chartType) && selectedItemscheckbox.size() > 1) { throw new ValidatorException(new FacesMessage("Max 1 item allowed")); } else if ("BarChart". Equals(chartType) && selectedItemscheckbox.size() > 2) { throw new ValidatorException(new FacesMessage("Max 2 items allowed")); } } } Note that I assume the #{bean. SelectedItemscheckbox} to be a List.
If it's actually a String, then you need to alter the validator code accordingly.
Thank you for the reply ,I have tried your proposition but an error occurred , I have updated my post with the error – rym Jul 27 at 8:52 You should not create the validator as a nested class. Do you understand when you may or may not create a nested class? – BalusC Jul 27 at 11:24.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.