Default selection for within

<h:selectOneMenu id=”items” value=”#{bean.selectedItem}”> <f:selectItem itemLabel=”10″ itemValue=”10″/> <f:selectItem itemLabel=”20″ itemValue=”20″/> <f:selectItem itemLabel=”30″ itemValue=”30″/> </h:selectOneMenu> The default selection would be the one which has value same as selectedItem which you set in bean. selectedItem = 20;

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

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

How to populate options of h:selectOneMenu from database?

Based on your question history, you’re using JSF 2.x. So, here’s a JSF 2.x targeted answer. In JSF 1.x you would be forced to wrap item values/labels in ugly SelectItem instances. This is fortunately not needed anymore in JSF 2.x. Basic example To answer your question directly, just use <f:selectItems> whose value points to a … Read more

Validation Error: Value is not valid

Validation fails with the message “form:location: Validation Error: Value is not valid” This error boils down to that the selected item does not match any of the available select item values specified by any nested <f:selectItem(s)> tag during processing of the form submit request. As part of safeguard against tampered/hacked requests, JSF will reiterate over … Read more

How to use enum values in f:selectItem(s)

JSF has a builtin converter for enum, so this should do: @Named @ApplicationScoped public class Data { public Status[] getStatuses() { return Status.values(); } } with <h:selectOneMenu value=”#{bean.question.status}” > <f:selectItems value=”#{data.statuses}” /> </h:selectOneMenu> (note: since JSF 2.0 there’s no need anymore to provide a SelectItem[] or List<SelectItem>, a T[] and List<T> are accepted as well … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)