list - How to enable/disable item in selecManyCheckbox based on flag -
i need in disabling , enabling item selectmanycheckbox component in jsf page. first of all, selectmanycheckbox component showing 3 chechboxes (loan - health - transfer). list populated bean has code:
private list<hrcertificate> hrcertificateslist = new arraylist<hrcertificate>(); //getter , setter private string loanflag=""; @postconstruct public void init() { this.hrcertificateslist.add(new hrcertificate(("loan"), "lc")); this.hrcertificateslist.add(new hrcertificate(("health"), "hi")); this.hrcertificateslist.add(new hrcertificate(("trasnfer"), "te")); } in same bean, running sql statement return either yes or no , value adding loanflag variable.so if flag="y", need enable loan checkbox user can select else need disable selectmanycheckbox. issue facing difficulties in applying logic disable , enable item selectmanycheckboxwhere in above code listing , enabling them time.
the code selectmanychexkbox:
<p:selectmanycheckbox id="hrcertificates" value="#{user.selectedhrcertificates}" layout="pagedirectio> <f:selectitems value="#{user.hrcertificateslist}" var="hrcertificate" itemlabel="#{hrcertificate.hrcertificatename}" itemvalue="#{hrcertificate.hrcertificatecode}"/> </p:selectmanycheckbox> so how apply logic
could edit hrcertificate class add disabled boolean field? if yes, can add itemdisabled="#{hrcerticate.disabled}" f:selectitems should easiest solution.
another option use map<hrcertificate, boolean> instead of list<hrcertificate>.
private map<hrcertificate, boolean> hrcertificatesmap = new hashmap<hrcertificate, boolean>(); @postconstruct public void init() { hrcertificatesmap.put(new hrcertificate(("loan"), "lc"), null); hrcertificatesmap.put(new hrcertificate(("health"), "hi"), null); hrcertificatesmap.put(new hrcertificate(("trasnfer"), "te"), null); } // when you're done sql query, update map add corresponding boolean values... .xhtml
<p:selectmanycheckbox id="hrcertificates" value="#{user.selectedhrcertificates}" layout="pagedirectio> <f:selectitems value="#{user.hrcertificatesmap.keyset().toarray()}" var="hrcertificate" itemlabel="#{hrcertificate.hrcertificatename}" itemvalue="#{hrcertificate.hrcertificatecode}" itemdisabled="#{user.hrcertificatesmap.get(hrcertificate)}" /> </p:selectmanycheckbox>
Comments
Post a Comment