p:selectOneMenu preselects previous item when noSelectionOption item is present

前端 未结 1 1761
梦毁少年i
梦毁少年i 2021-01-19 01:52

There is a problem with p:selectOneMenu selection when adding a f:selectItem.

View:



        
1条回答
  •  终归单人心
    2021-01-19 02:20

    I could reproduce your problem. I looked in the PrimeFaces source code. It's a bug in PrimeFaces SelectOneMenuRenderer which exposes only when an item with noSelectionOption="true" is been used. The renderer won't generate the HTML element of the backing contains in your case 4 items and the

      5 items. The
    • is selected by JavaScript based on the index of the , exactly as you suspected. That explains your problem.

      Your best bet is to report it as a bug to PrimeFaces guys. The renderer should also generate the for that, or the JavaScript should select the option based on value instead of on index.

      In the meanwhile, replacing the noSelectionOption="true" by itemValue="#{null}", or also itemValue="" when JSF is configured to interpret empty string submitted values as null, should solve your problem.

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