title: JSF + HashMap and its key
body: <p>I have a database with 2 tables <code>CD</code> and <code>Song</code>. Session bean access then entity classes of those two tables. In my backing bean, I just have a <code>String cd</code> and <code>HashMap&lt;CDName, CDName&gt; cds</code> that will hold the list of CD return back from my sessionbean, so in JSF I would do something like this. </p>
  
  <pre><code>&lt;h:selectOneMenu id="cd" value="#{backingBean.cd}"&gt;
       &lt;f:selectItem itemLabel="Select CD" itemValue="" /&gt;
       &lt;f:selectItems value="#{backingBean.cds}" /&gt;
  &lt;/h:selectOneMenu&gt;
  </code></pre>
  
  <p>This successfully load a list of cd onto the drop down list, and if I select a cd, <code>cd</code> variables would hold the name of the CD I select. This work great if <code>CDName</code> is unique. But unfortunately it is not. So what I want is <code>HashMap&lt;ID, CDName&gt; cds</code> where <code>ID</code> is the PK in table <code>CD</code>. But now how I can set it up, so when I click on a item from the CD drop down list, I get the <code>ID</code> back in my backingbean, so that I can do something like this, in my session bean</p>
  
  <pre><code>CD cd = EntityManager.find(CD.class, the id that I get back from JSF page)
  </code></pre>
  
  <p>essentially I want to obtain the <code>cd</code> object that I just click on, keep it in mind, there might be duplication. If my design is bad, please point out. Help please. Thanks in advance</p>