Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to bind the selected value in selectOneMenu
    primarykey
    data
    text
    <p>Of five options in a selectOneMenu I chose the second option and persisted the entity. On edit the persisted entity selectOneMenu always has the last option as its value.</p> <p>For example,</p> <pre><code>&lt;h:selectOneMenu value="#{userHome.user.leader}"&gt; &lt;f:selectItems value="#{userHome.availableLeaders}" var="leader" itemLabel="# {leader.name}" itemValue="#{leader}"/&gt; &lt;/h:selectOneMenu&gt; </code></pre> <p>where availableLeaders is a list of users populated @PostConstruct method.</p> <p>I am expecting the selectOneMenu to have the second option(chosen) on edit.</p> <pre><code>@FacesConverter(forClass = User.class, value = "userConverter") public class UserConverter implements Converter { public UserConverter() { } @Override public Object getAsObject(FacesContext context, UIComponent component, String value) { EntityManagerFactory emf = Persistence.createEntityManagerFactory("DefaultPersistenceUnit"); EntityManager em = emf.createEntityManager(); Query q = em.createQuery("select query"); return q.resultList().get(0); } @Override public String getAsString(FacesContext context, UIComponent component, Object value) { return ((User) value).getName(); }} </code></pre> <p>In User.java</p> <pre><code>public boolean equals(Object other) { if (this.getClass().isInstance(other)) { return true; } else { return false; } } public int hashCode() { HashCodeBuilder builder = new HashCodeBuilder(); builder.append(getId()); builder.append(getName()); return builder.toHashCode(); } </code></pre>
    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.
 

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