Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to avoid / suppress JSF <h:selectOneMenu /> null (no selection option) tab?
    primarykey
    data
    text
    <p>When creating a new item the user does not want to see the null no selection option in the Select-One Menu, but directly an item from the available items. So either to get rid of the null no option or display directly the second element in the dropdown. I tried the attribute <code>hideNoSelection</code>, but it does nothing. How can I achieve this?</p> <pre><code>&lt;h:selectOneMenu id="ugroup" value="#{usersController.selected.ugroup}" title="#{bundle.CreateUsersTitle_ugroup}" required="true" requiredMessage="#{bundle.CreateUsersRequiredMessage_ugroup}"&gt; </code></pre> <p></p> <pre><code>&lt;/h:selectOneMenu&gt; </code></pre> <p>----------------EDIT (after @Balus Answer) --------------------- Here is the Utility method that grabs JPA Lists to be displayed as a <code>&lt;h:selectOneMenu /&gt;</code> :</p> <pre><code>public class JsfUtil { public static SelectItem[] getSelectItems(List&lt;?&gt; entities, boolean selectOne) { int size = selectOne ? entities.size() + 1 : entities.size(); SelectItem[] items = new SelectItem[size]; int i = 0; if (selectOne) { // part to be removed items[0] = new SelectItem("", "---"); i++; } // end of part to be removed for (Object x : entities) { items[i++] = new SelectItem(x, x.toString()); } return items; } </code></pre> <p>So appearently, all I have to do is remove this part? :</p> <pre><code> if (selectOne) { items[0] = new SelectItem("", "---"); i++; } </code></pre> <p>But as this static method is used everywhere in my code, would it have any unwanted consequences?</p> <ul> <li><p>Like, when the user wants explicitly a null value from the <strong><code>&lt;h:selectOneMenu /&gt;</code></strong>, if he decides to choose no option. My guess was to use <strong><code>&lt;f:selectItem</code></strong> :</p> <p> </p> <p> </p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload