title: Accessing the EntityManager from a JSF Converter class
body: <p>I'm trying to write a converter class that will convert between an <code>Employee</code> object and a String (for display purposes). The end goal is to have a SelectOne field on a form which displays a list of all the employee numbers in the database.</p>
  
  <p>Here's what I have so far:</p>
  
  <pre><code>@FacesConverter(value = "employeeConverter")
  public class EmployeeConverter implements Converter {
  
      @Override
      public Object getAsObject(FacesContext context, UIComponent component, String value) {
          Employee tmp = Helper.findEmployee(em, value);
          return tmp;
      }
  
      @Override
      public String getAsString(FacesContext context, UIComponent component, Object value) {
          Employee tmp = (Employee) value;
          return tmp.getEMPLOYEE_NUMBER();
      }
  }
  </code></pre>
  
  <p>So, the issue I'm running into is that the <code>Helper</code> class (which basically runs SQL queries for me - I can include it if needed) requires that I pass it an <code>EntityManager</code>. As I've figured out through searching, I can't just include the EntityManager in this class because it's outside of the "scope" of the web stuff.</p>
  
  <p>I'm new to using Java for the web, and very new to using databases with Java. Can someone explain how I can use a converter this way to query my database and have a Select box with employee numbers in it.</p>