validation - How to set primefaces selectCheckboxMenu validator for minimum selects -


i want write validator primefaces selectcheckboxmenu prevent user selecting less 5 values.

i've tried implement balusc requiredcheckboxvalidator couldn't know how access size of selected values, can put me on right path?

you in way.

xhtml

<p:selectcheckboxmenu value="#{mainbean.selectedlist}" >       <f:selectitems value="#{mainbean.map}" />       <f:validator validatorid="limitcheckboxmenuvalidator" />                            <f:attribute name="minlimit" value="5" /> </p:selectcheckboxmenu>   

validator

@facesvalidator("limitcheckboxmenuvalidator") public class limitcheckboxmenuvalidator implements validator {     public limitcheckboxmenuvalidator() {     }     @override    public void validate(facescontext context, uicomponent component,            object value) throws validatorexception {         //get limit        integer minlimit =    integer.parseint((string)component.getattributes().get("minlimit"));        selectcheckboxmenu mycomponent = (selectcheckboxmenu)component;         if (((string[])mycomponent.getsubmittedvalue()).length < minlimit) {            facesmessage msg                    = new facesmessage("limit failed",                            "min selection must " + minlimit);            msg.setseverity(facesmessage.severity_error);            throw new validatorexception(msg);        }     } } 

a small working example can found on github [1] [2], , online demo.

hope helps.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -