Using a “Please select” f:selectItem with null/empty value inside a p:selectOneMenu

后端 未结 6 1053
粉色の甜心
粉色の甜心 2020-11-28 10:08

I\'m populating a from database as follows.



        
6条回答
  •  [愿得一人]
    2020-11-28 10:37

    You're mixing a few things, and it's not fully clear to me what you want to achieve, but let's try

    This obviously causes the java.lang.NumberFormatException to be thrown in its converter.

    It's nothing obvious in it. You don't check in converter if value is empty or null String, and you should. In that case the converter should return null.

    Why does it render Select (itemLabel) as its value and not an empty string (itemValue)?

    The select must have something selected. If you don't provide empty value, the first element from list would be selected, which is not something that you would expect.

    Just fix the converter to work with empty/null strings and let the JSF react to returned null as not allowed value. The conversion is called first, then comes the validation.

    I hope that answers your questions.

提交回复
热议问题