How to select the first item in a list in & lt; H: selectOneMenu & gt; And render the page during the initial load for the first selected item


I have following code:

<h:selectOneMenu value="#{AssetSummaryPageModel.selectedSensorId}"                                  styleClass="facility_dropDown_list" required="true" >

<f:selectItems value="#{AssetSummaryPageModel.childFacilitySelectionList}" required="true" />
<a4j:ajax event="valueChange" execute="@this" status="nameStatus"

When I select one item from the dropdown, it is rendering the page for the selected item. But, I want to render the page (with the first item of the dropdown list) during initial load. How can I do that. Any help please!!!!

That's easy. in your AssetSummaryPageModel-Bean you will add a new method with the @PostConstruct annotation so it will be called after the bean has been constructed. In this method you will set selectedSensorId to the first item of your childFacilitySelectionList.

When your page is being rendered, JSF will see that a value was already selected and will set this one as the selected one.

public void init() {
    selectedSensorId = childFacilitySelectionList.get(0);