title: How to use an Enum in p:selectOneMenu
body: <p>In my JSF/PrimeFaces mini web project I want to use a drop down list to select Enum items, then add them to a database when I fill in the 'create' form.<br>
  I used Netbeans to create an Entity class from a database, and then used to the wizard 'JSF pages from Entity classes', with PrimeFaces as the template. This creates Create / Edit / List / View xhtml pages automatically.
  At the moment I've got:</p>
  
  <p><strong>Enum class:</strong></p>
  
  <pre><code>    public enum InterestsEnum {
      FOOTBALL,
      SKIING,
      CYCLING,
      MUSIC;
  
  }
  </code></pre>
  
  <p><strong>Entity class:</strong></p>
  
  <pre><code>    @Entity
  public class Person implements Serializable {
  
      @Column(name="ID")
      @Id
      @NotNull
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long personId;
  
      @Column(name="FIRSTNAME")
      @Basic(optional=false)
      @NotNull
      @Size(min=1,max=45)
      private String firstName;
  
      @Column(name="SURNAME")
      @Basic(optional=false)
      @NotNull
      @Size(min=1,max=45)
      private String surname;
  
      @ElementCollection(fetch = FetchType.EAGER, targetClass = InterestsEnum.class)
      @JoinTable(name = "Person_INTERESTS", joinColumns = @JoinColumn(name = "PERSON_ID"))
      @Column(name = "INTERESTS", nullable = false)
      @Enumerated(EnumType.STRING)
      Collection&lt;InterestsEnum&gt; interests;
  
      //Getters and Setters:
  </code></pre>
  
  <p><strong>Managed Bean:</strong></p>
  
  <pre><code>@ManagedBean
  @ApplicationScoped
  public class Data {
  
      public InterestsEnum[] getInterests() {
          return InterestsEnum.values();
      }
  }
  </code></pre>
  
  <p><strong>PrimeFaces Create page extract:</strong></p>
  
  <pre><code>&lt;p:selectOneMenu value="#{person.interests}" &gt;
      &lt;f:selectItems value="#{InterestsEnum}" /&gt;
  &lt;/p:selectOneMenu&gt;
  </code></pre>
  
  <p><strong>PrimeFaces List page extract:</strong></p>
  
  <pre><code>                        &lt;p:column&gt;
                          &lt;f:facet name="header"&gt;
                              &lt;h:outputText value="#{bundle.ListPersonTitle_interests}"/&gt;
                          &lt;/f:facet&gt;
                          &lt;h:outputText value="#{item.interests}"/&gt;
                      &lt;/p:column&gt;
  </code></pre>
  
  <p>When I run the project there are no errors until I open 'List', when the following happens: </p>
  
  <pre><code>    Severe:   Error Rendering View[/person/List.xhtml]
  javax.faces.FacesException: Cannot find component with expression "interests" referenced from "PersonCreateForm:j_idt34".
      at org.primefaces.expression.SearchExpressionFacade.resolveComponentInternal(SearchExpressionFacade.java:422)
      at org.primefaces.expression.SearchExpressionFacade.resolveComponent(SearchExpressionFacade.java:266)
      at org.primefaces.expression.SearchExpressionFacade.resolveComponent(SearchExpressionFacade.java:228)
      at org.primefaces.component.outputlabel.OutputLabelRenderer.encodeEnd(OutputLabelRenderer.java:47)
      at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:920)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
      at org.primefaces.component.panelgrid.PanelGridRenderer.encodeDynamicBody(PanelGridRenderer.java:89)
      at org.primefaces.component.panelgrid.PanelGridRenderer.encodeBody(PanelGridRenderer.java:60)
      at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:49)
      at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:920)
      at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312)
      at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:114)
      at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:890)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
      at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
      at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:890)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
      at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:582)
      at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
      at javax.faces.component.UIForm.visitTree(UIForm.java:381)
      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
      at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:403)
      at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:322)
      at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60)
      at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:1004)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
      at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:432)
      at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:134)
      at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
      at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
      at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
      at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
      at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
      at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
      at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
      at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
      at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
      at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
      at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
      at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
      at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
      at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
      at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
      at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>If I submit the 'create' form I get the following error:</p>
  
  <pre><code>Severe:   javax.faces.component.UpdateModelException: javax.el.PropertyNotFoundException: /person/Create.xhtml @24,71 value="#{Person.interests}": Target Unreachable, identifier 'Person' resolved to null
  </code></pre>
  
  <p>There is no drop down list to select Enum choices from (see screenshot). Also 'List' shows all the Enum members, not just one.</p>
  
  <p><a href="https://i.stack.imgur.com/4WoUR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4WoUR.png" alt="PrimeFaces List / Create"></a></p>