p:selectOneMenu does not set value in bean

后端 未结 4 1671
孤城傲影
孤城傲影 2021-02-07 10:43

Quick question. This hasn\'t happened to me before when working with SelectOneMenu. This is my code.



        
相关标签:
4条回答
  • 2021-02-07 10:53

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

    0 讨论(0)
  • 2021-02-07 11:01

    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.

    0 讨论(0)
  • 2021-02-07 11:11

    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.

    0 讨论(0)
  • 2021-02-07 11:12
    <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.

    0 讨论(0)
提交回复
热议问题