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

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

I\'m populating a from database as follows.



        
6条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 10:30

    • If you want to avoid null values for your select component, the most elegant way is to use the noSelectionOption.

    When noSelectionOption="true", the converter will not even try to process the value.

    Plus, when you combine that with you will get a validation error, when user tries to select that option.

    One final touch, you can use the itemDisabled attribute to make it clear to the user that he can't use this option.

    
    
        
    
        
    
        
    
    
    
    
    • Now if you do want to be able to set a null value, you can 'cheat' the converter to return a null value, by using

      
      

    More reading here, here, or here

提交回复
热议问题