I'm trying to write a converter class that will convert between an Employee
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.
Here's what I have so far:
@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();
}
}
So, the issue I'm running into is that the Helper
class (which basically runs SQL queries for me - I can include it if needed) requires that I pass it an EntityManager
. 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.
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.