java - How to populate a dropdown on page load in jsf? -
this question has answer here:
i'm new jsf, read jsf life cycle couldn't understand how achieve this?
i've controller "cities" , other controller "countries". i'm going create new page, provide search functionality. showed 2 dropdowns on page (one countries , other cities), want first drop down populated on page load. please tell me controller use? cities/countries? or create new one? , how load data on page load?
thanks!
everyone correct, need use <f:selectitems/>
example:
.xhtml
<h:selectonemenu> <f:selectitems value="#{mycontroller.listitems}"/> </h:selectonemenu>
bean
public class mycontroller{ //the list items private list<selectitem> listitems = null; public mycontroller { loadcombo(); } (...) //loading items private void loadcombo() { listitems = new arraylist<selectitem>(); //you can bd data using for. how add new item: //listitems.add(new selectitem("itemvalue", "itemlabel")); listitems.add(new selectitem("1", "item 1")); listitems.add(new selectitem("2", "item 2")); listitems.add(new selectitem("3", "item 3")); listitems.add(new selectitem("4", "item 4")); } (...) //getters , setters }
do not populate list in "get" method, because jsf call more once , kill performance.
Comments
Post a Comment