JSF f:selectItems设置项目(复制)

时间:2023-01-19 09:08:12

This question already has an answer here:

这个问题已经有了答案:

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:

anios被定义为:

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.

选择的值是2014年,但我想要的是2016年。如何做到这一点呢?我用Primefaces。

1 个解决方案

#1


0  

You must include the attribute "value" in the element "selectOneMenu". Something like that:

您必须在元素“selectOneMenu”中包含属性“值”。这样的:

<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

然后在您的bean (pruebaCalendarBean)中,您必须定义一个新属性,在这个例子中,“anioSeleccionado”表示下拉菜单中所选的值。

#1


0  

You must include the attribute "value" in the element "selectOneMenu". Something like that:

您必须在元素“selectOneMenu”中包含属性“值”。这样的:

<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

然后在您的bean (pruebaCalendarBean)中,您必须定义一个新属性,在这个例子中,“anioSeleccionado”表示下拉菜单中所选的值。