问题
I have a <f:selectItems>
as follows:
<p:selectOneMenu id="anios">
<f:selectItems value="#{pruebaCalendarBean.anios}" var="anio" itemLabel="#{anio}" itemValue="#{anio}" />
</p:selectOneMenu>
anios is defined as:
String[] anios = new String[]{"2014","2015","2016","2017"};
The value selected is 2014, but I want that is 2016. How to do this? I'm using Primefaces.
回答1:
You must include the attribute "value" in the element "selectOneMenu". Something like that:
<p:selectOneMenu id="anios" value="#{pruebaCalendarBean.anioSeleccionado}">
<f:selectItems value="#{pruebaCalendarBean.anios}" var="anio" itemLabel="#{anio}" itemValue="#{anio}" />
</p:selectOneMenu>
Then in your bean (pruebaCalendarBean) you must define a new attribute, in this case "anioSeleccionado" that represents the selected value in the dropdown
来源:https://stackoverflow.com/questions/21788241/jsf-fselectitems-set-item-selected