Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3282892
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:58:44+00:00 2026-05-17T19:58:44+00:00

Thanks to some great articles here, I’ve been able to build a <h:selectOneMenu />

  • 0

Thanks to some great articles here, I’ve been able to build a <h:selectOneMenu /> with selectItems containing objects. After providing a custom FacesConverter and fixing the missing equals()/hashcode() methods, I am able to use it to change the property of the backing bean and write it out to the DB.

The only weird thing is that all HTML <option /> elements of the <select />-element are checked="checked"! In other words: the <h:selectOneMenu /> does not reflect the current value of the bound property!

Details:

Store.java

@Entity
public class Store {
  private Long id;
  private String name;

  @ManyToOne
  private Category category;

  // getters, setters, equals, hashcode
}

Category.java

@Entity
public class Category {
  private Long id;
  private String name;

  // getters, setters, equals, hashcode
}

editStore.xhtml

<h:form>
....
  <h:selectOneMenu value="#{backingBean.store.category}" id="category">
    <f:selectItems value="#{backingBean.categorySelectItems}" />
  </h:selectOneMenu>
....
</h:form>

BackingBean.java

public class BackingBean {
  private Store store;

  // inject data-access-facades via @EJB
  // Constructor
  // getters, setters

  public List<SelectItem> getCategorySelectItems
    List<SelectItem> items = new ArrayList<SelectItem>();
    for (Category cat : categoryFacade.findAll() ) {
      items.add(new SelectItem(cat, cat.getName()));
    }
    return items;
  }

  // action methods
}

I leave out listing the Category-Converter (it converts between the object and its ID).

The HTML this creates is:

<select id="category" name="category" size="1">
  <option value="251" selected="selected">Kosmetik</option>
  <option value="222" selected="selected">Sportwaren</option>
</select>

Obviously, store.category can only contain one item… why are both option-elements “selected”? No matter, what category is assigned to the store, the HTML always “selects” all option-elements.

How does JSF now, which SelectItem should be selected?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:58:45+00:00Added an answer on May 17, 2026 at 7:58 pm

    It’s almost certain that the problem is in the equals(..) method, which returns true for all compared objects. Test this, and let your IDE generate the method (together with hashCode())

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks to some great folks on SO, I discovered the possibilities offered by collections.defaultdict
I'm having trouble with http://developer.android.com/resources/articles/painless-threading.html It's been touted as a great source of information
Ive gotten some great help here and I am so close to solving my
I've been doing some reading on PHP security and I ran into a great
Thanks to some help I received yesterday I've got some dynamic summing working on
This question is related to another question of mine. Thanks to some help I
Thanks for taking some time to help me out. Using: Microsoft Visual C# 2010
I had some troubles implementing Lawler's algorithm but thanks to SO and a bounty
Some background: I've created a Swing application which uses the Substance LaF (Thanks again,
Thanks in advance. How can I stop downloading when some events occurred in wp7.For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.