I am making a web-based application using SEAM and JBOSS. I am trying to make a converter for a drop-down box, but whenever I use entityManager within the converter class I get a NullPointerException. I have spent a couple days trying to figure this help and any help would be appreciated
Here is some of my code. If anymore is needed, just let me know:
Converter Class:
package edu.uwrf.iss.flowershop.entity;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.servlet.ServletContext;
import javax.swing.JOptionPane;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Scope;
public class EmpConverter implements Converter {
@In
private EntityManager entityManager;
public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
int num = Integer.parseInt(arg2);
entityManager.refresh(getClass());
Query query = entityManager.createQuery("SELECT e FROM FlowerStoreDelivery WHERE e.deliveryId LIKE :num")
.setParameter("num", num);
JOptionPane.showMessageDialog(null, query.getResultList());
FlowerStoreEmployee emp = entityManager.find(FlowerStoreEmployee.class, arg2);
return emp;
}
public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) throws ConverterException {
return Integer.toString(((FlowerStoreEmployee)arg2).getEmployeeId());
}
}
And this is where the converter is used:
<my:dropdown label="Employee ID" id="emp" value="#{deliveryPort.emp}"required="false">
<f:converter converterId="EmpConverter" />
<s:selectItems value="#{deliveryPort.empList}" var="emp" label="#{emp.employeeId} #{ emp.nameFirst}"/>
</my:dropdown>
I have figured the problem out. There was a missing line of code in my components.xml file. Thank you all for your responses.