JSF f:selectItems set item selected [duplicate]

限于喜欢 提交于 2019-12-11 14:26:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!