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