Hi, I am new to JSF and struggling to understand how a combo box can be prepopulated on page startup.
My code is as follows: <h:selectOneMenu id="selectCar" value="#{Cars.currentCar}"> <f:selectItems value="#{Cars.carList}" /> </h:selectOneMenu>
The carListproperty should be set with data from the database.
Can the Cars managed bean make a call to the server side to populate itself or is there somekind of a controller to do the job before the page is displayed.
JSF uses the method binding to get a list to populate the combo box. So just have the getCarList() method return the list you want e.g. by creating the list itself, or calling some other object which does so.
OK, related question. How do you get the combo box to select the current value from the bean on page population? I can't seem to get the list to coordinate with the value chosen. Thanks
Originally posted by Paul Smiley: OK, related question. How do you get the combo box to select the current value from the bean on page population? I can't seem to get the list to coordinate with the value chosen. Thanks
Well, I have a HtmlSelectOneMenu component that has a value of 1 member of the backing bean and the SelectItem options are populated with another member which is a list of potential values. When the page renders, the first element of the list always displays in the list, not the current value as held in the backing bean element 1. It seems like some type of translation to the Html Option selected="true" needs to be rendered, but I don't know how to do it. It seems like the data element is not bound to the component. Thanks, Paul
Originally posted by Paul Smiley: Well, I have a HtmlSelectOneMenu component that has a value of 1 member of the backing bean and the SelectItem options are populated with another member which is a list of potential values. When the page renders, the first element of the list always displays in the list, not the current value as held in the backing bean element 1. It seems like some type of translation to the Html Option selected="true" needs to be rendered, but I don't know how to do it. It seems like the data element is not bound to the component. Thanks, Paul