Populate p:selectOneMenu based on another p:selectOneMenu in each row of a p:dataTable

Whilst your initial solution works, it’s in fact inefficient. This approach basically requires the entire object graph of the Country and State tables (even with circular references) to be fully loaded in Java’s memory per JSF view or session even though when you simultaneously use only e.g. 5 of 150 countries (and thus theoretically 5 … Read more

Conditionally render a component based on selectOneMenu value

Just check the dropdown menu’s value in the rendered attribute of the target components and update their common parent by a <f:ajax>. Here’s a kickoff example: <h:selectOneMenu value=”#{bean.item}”> <f:selectItem itemValue=”one” /> <f:selectItem itemValue=”two” /> <f:selectItem itemValue=”three” /> <f:ajax render=”results” /> </h:selectOneMenu> <h:panelGroup id=”results”> <h:panelGroup rendered=”#{bean.item eq ‘one’}”> You have selected “one”. </h:panelGroup> <h:panelGroup rendered=”#{bean.item eq … Read more

How do UISelectOne and UISelectMany components preselect defaults in f:selectItems

It uses Object#equals() for that. You can change (fix) this behavior by implementing it accordingly on your entity. private Long id; @Override public boolean equals(Object other) { return (other != null && getClass() == other.getClass() && id != null) ? id.equals(getClass().cast(other).id) : (other == this); } Don’t forget the hashCode() to satisfy the equals-hashCode contract. … Read more

How to add tooltip to f:selectItems

Would it be possible to replace JSF Components by their plain HTML counterparts using JSFC and do something like this Nope. Ultimately, such a HTML element with jsfc attribute will be turned into a true JSF component in the JSF component tree and only the attributes supported by the component in question would be parsed … Read more

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

When the select item value is null, then JSF won’t render <option value>, but only <option>. As consequence, browsers will submit the option’s label instead. This is clearly specified in HTML specification (emphasis mine): value = cdata [CS] This attribute specifies the initial value of the control. If this attribute is not set, the initial … 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

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