JSF f:selectItems设置选择的项目 [英] JSF f:selectItems set item selected

查看:144
本文介绍了JSF f:selectItems设置选择的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个<f:selectItems>,如下:

<p:selectOneMenu id="anios">
    <f:selectItems value="#{pruebaCalendarBean.anios}" var="anio" itemLabel="#{anio}" itemValue="#{anio}"  />
</p:selectOneMenu>

anios定义为:

String[] anios = new String[]{"2014","2015","2016","2017"};

选择的值是2014,但我想要的是2016.该怎么做?我正在使用Primefaces.

The value selected is 2014, but I want that is 2016. How to do this? I'm using Primefaces.

推荐答案

您必须在元素"selectOneMenu"中包括属性"value".像这样的东西:

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>

然后,在您的bean(pruebaCalendarBean)中,您必须定义一个新属性,在这种情况下为"anioSeleccionado",它代表下拉列表中的选定值

Then in your bean (pruebaCalendarBean) you must define a new attribute, in this case "anioSeleccionado" that represents the selected value in the dropdown

这篇关于JSF f:selectItems设置选择的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆