Best way to add a “nothing selected” option to a selectOneMenu in JSF

Just explicitly set the select item value to null. <h:selectOneMenu value=”#{bean.selectedItem}”> <f:selectItem itemValue=”#{null}” itemLabel=”–select–” /> <f:selectItems value=”#{bean.availableItems}” /> </h:selectOneMenu> No, an empty string like itemValue=”” is not sufficient. It really has to be null. Otherwise you run into trouble as described in this Q&A: Using a “Please select” f:selectItem with null/empty value inside a p:selectOneMenu. … Read more

Conversion Error setting value for ‘null Converter’ – Why do I need a Converter in JSF?

Introduction JSF generates HTML. HTML is in Java terms basically one large String. To represent Java objects in HTML, they have to be converted to String. Also, when a HTML form is submitted, the submitted values are treated as String in the HTTP request parameters. Under the covers, JSF extracts them from the HttpServletRequest#getParameter() which … Read more