jsf - <f:selectItems is not returning value in <p:selectOneMenu> -
i have problem getting value of f:selectitems returning label.
here code;
<p:selectonemenu>. <p:outputlabel value="major diseases"></p:outputlabel> <p:selectonemenu value="#{datamigeration.mdid}"> <f:selectitem itemlabel="select one" itemvalue="" /> <f:selectitems var="t" value="#{datamigeration.majordiseas}" itemlabel="#{t.value.mdname}" itemvalue="#{t.value}"/> <p:ajax listener="#{datamigeration.getsubdiseasesbymojardisease(datamigeration.mdid)}" event="change" update="datamigration"/> </p:selectonemenu>
here datamigeration class
@managedbean(name="datamigeration") @sessionscoped public class datamigeration{ string mdid; private list<selectitem> majordiseas = new arraylist<selectitem>(); public list<selectitem> getmajordiseas() { majordiseas = new arraylist<selectitem>(); system.out.println("datamigeration.getmajordiseas():"); list<diseasecategory> majordiseaseslist = new arraylist<diseasecategory>(); majordiseaseslist=datamanager.findallrecords(); (diseasecategory obj : majordiseaseslist) { majordiseas.add(new selectitem(obj.getmdid(), obj.getmdname())); } return majordiseas; } public void getsubdiseasesbymojardisease(string mdid) { system.out.println("\n\n\n\n | value:"+mdid); }
but getting mdid=itemlabel of f:selecteditem want itemvalue of f:selectem. somewhere have done before forgot how itemvalue.
your 'f:selectitems' statement wrong. can use 'var' attribute loop through list of complex java objects dynamically create list of selectitem objects. (see http://www.mkyong.com/jsf2/jsf-2-dropdown-box-example/ examples)
but in case, you've created list of selectitem objects in backing bean, reference instead:
<f:selectitems value="#{datamigeration.majordiseas}" />
Comments
Post a Comment