p:selectOneMenu does not set value in bean

雨燕双飞 提交于 2019-12-03 10:42:24

I found the error and it was ... quite strange and circumstantial. I added the following line inside the SelectOneMenu:

<p:ajax event="change" update="@this" />

and now it works just fine.

<p:selectOneMenu id="listaRegiones" value="#{nuevaProvincia.regionSelect}" required="true">
    <f:selectItems value="#{nuevaProvincia.regiones}" />
</p:selectOneMenu>

should be

<p:selectOneMenu id="listaRegiones" value="#{nuevaProvincia.regionSelect}" required="true">
    <f:selectItems value="#{nuevaProvincia.regiones}" var="region" 
      itemValue = "#{region}"/>
</p:selectOneMenu>

That's why you have to have the ajax call to update whenever there is a change. You are never setting the value.

If you are working objects in the value, check the equals() function.

Rogério Marchiori

I discovered when I had this problem it was because of the @ViewScoped. Using SessionScoped instead worked fine.

One interesting thing is that in another project, with ViewScoped, it worked. I cannot explain.

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