title: How to use Primefaces autocomplete with a POJO List and a POJO's property as selection value
body: <p>In our current project we want to replace a <code>&lt;h:selectOneMenu&gt;</code> with Primefaces's <code>&lt;p:autocomplete&gt;</code>. The select items are a list of Pojos (JPA Entities). The difference to the given examples in primefaces <a href="http://www.primefaces.org/showcase/ui/autoCompletePojo.jsf" rel="nofollow">showcases</a> is, that we want the primary key property (id) of the entity as selection value, so it can be easily passed as view param:</p>
  
  
  
  <pre class="lang-xml prettyprint-override"><code>&lt;f:metadata&gt;
      &lt;f:viewParam name="playerId" value="#{playerPreRenderViewListener.searchCriteria.playerId}" /&gt;
      &lt;f:viewParam name="year" value="#{playerPreRenderViewListener.searchCriteria.year}" /&gt;
  &lt;/f:metadata&gt;
  &lt;h:form&gt;
      &lt;h:inputText value="#{playerPreRenderViewListener.searchCriteria.year}"/&gt;
      &lt;p:autoComplete var="player" itemLabel="#{player.name}" itemValue="#{player.id}"
          completeMethod="#{playerBean.completePlayer}" forceSelection="true"
          converter="#{playerConverter}" 
          value="#{playerPreRenderViewListener.searchCriteria.playerId}"&gt;
      &lt;/p:autoComplete&gt;
      &lt;h:commandButton value="Submit" action="showTeam?faces-redirect=true&amp;amp;includeViewParams=true" /&gt;
  &lt;/h:form&gt;
  </code></pre>
  
  <p>Unfortunately the example above will lead to a PropertyNotFoundException:</p>
  
  <blockquote>
    <p>itemLabel="#{player.name}": Property 'name' not found on type java.lang.Long'</p>
  </blockquote>
  
  <p>The problem is that the <code>var</code> attribute is of Type <code>Long</code> and not <code>Player</code>. When using a simple <code>&lt;h:selectMenu&gt;</code> it works in conjunction with <code>&lt;f:selectItems&gt;</code>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;f:selectItems var="player" value="#{playerBean.listPlayers}" itemLabel="#{player.name}" itemValue="#{player.id}" /&gt;
  </code></pre>
  
  <p>Does anybody know how to handle this issue?</p>