title: SelectOneMenu always shows first item not the selected - Primefaces
body: <p>Some help would be appreciated on this issue.</p>
  
  <p>I have several JSF Pages, but one of them is a Subcategory where there is a <strong>SelectOneMenu</strong> for choosing the <strong>Category</strong>, but when I try to edit the subcategory, this <strong>SelectOneMenu</strong> always shows the first value and is not getting preselected. </p>
  
  <p>How could I solve this. I have read a lot of <strong>SO posts</strong> and eventhougn I have implemented a couple of advice I have not achieved it. for example, a <strong>@BalusC</strong>'s one:</p>
  
  <p><a href="https://stackoverflow.com/questions/10726716/primefaces-selectonemenu-doesnt-working-when-it-should">primefaces selectOneMenu doesn&#39;t working when it should</a>       </p>
  
  <p><strong>Here is the View</strong> </p>
  
  <pre><code>&lt;h:outputText value="Subcategory ID : #{subcategoryController.subcategory.subcategoryId}"/&gt;
  
  &lt;p:selectOneMenu id="cboCategoryDialog" converter="subcategoryConverter"
                   value="#{subcategoryController.category.categoryId}"
                   style="width: 100%"
  
      &lt;f:selectItems value="#{subcategoryController.categoryList}"
                     var="subcat"
                     itemLabel="#{subcat.categoryName}"
                     itemValue="#{subcat.categoryId}"/&gt;
  &lt;/p:selectOneMenu&gt;**
  </code></pre>
  
  <p><strong>This is the Subcategory Entity:</strong></p>
  
  <pre><code>private static final long serialVersionUID = 1L;
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Basic(optional = false)
  @Column(name = "subcategory_id")
  private Integer subcategoryId;
  @Basic(optional = false)
  @NotNull
  @Size(min = 1, max = 45)
  @Column(name = "subcategory_name")
  private String subcategoryName;
  @JoinColumn(name = "category_id", referencedColumnName = "category_id")
  @OneToOne(optional = false;
  private Category categoryId;
  
  //Getters and Setters Methods
  
  @Override
  public int hashCode() {
      return (subcategoryId != null)
              ? (this.getClass().hashCode() + subcategoryId.hashCode())
              : super.hashCode();
  }
  
  @Override
  public boolean equals(Object obj) {
  
      return (obj instanceof Subcategory) &amp;&amp; (subcategoryId != null)
              ? subcategoryId.equals(((Subcategory) obj).subcategoryId)
              : (obj == this);
  }
  </code></pre>
  
  <p><strong>SubcategoryConverter</strong></p>
  
  <pre><code>@RequestScoped
  @FacesConverter("subcategoryConverter")
  public class SubcategoryConverter implements Converter {
  
  @EJB
  private SubcategoryFacadeLocal EJBsubcategory;
  
  @Override
  public String getAsString(FacesContext context, UIComponent component, Object value) {
      if (!(value instanceof Subcategory) || ((Subcategory) value).getSubcategoryId() == null) {
          return null;
      }
  
      return String.valueOf(((Subcategory) value).getSubcategoryId());
  }
  
  @Override
  public Object getAsObject(FacesContext context, UIComponent component, String value) {
      if (value == null || !value.matches("\\d+")) {
          return null;
      }
  
      Subcategory subcategory = EJBsubcategory.find(Integer.valueOf(value));
  
      if (subcategory == null) {
          throw new ConverterException(new FacesMessage("Unknown operation ID: " + value));
      }
  
      return subcategory;
  
      }
  }
  </code></pre>
  
  <p>Below image shows the Dialog when I try to edit any item, it always shows computer because its the first itm.</p>
  
  <p><a href="https://i.stack.imgur.com/UgUeI.jpg" rel="nofollow noreferrer">See the image showing the issue</a></p>
  
  <p>I have been reading some related useful questions about this, but I have not been able to fix it.</p>
  
  <p>Thanks in advance,</p>