0

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.

Luiggi Mendoza
  • 81,685
  • 14
  • 140
  • 306
victorpacheco3107
  • 752
  • 3
  • 10
  • 26

1 Answers1

0

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

wezki
  • 1