我正在使用SEAM和JBOSS製作一個基於Web的應用程序。我正在嘗試爲下拉框創建一個轉換器,但是無論何時在轉換器類中使用entityManager,我都會得到一個NullPointerException。我花了幾天試圖找到這個幫助和任何幫助,將不勝感激EntityManager導致nullPointerException。使用Seam和JBOSS
這是我的一些代碼。如果不再需要,只要讓我知道:
轉換器類:
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());
}
}
這是第一個使用轉換器:
<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>
entityManager.refresh()調用的要點是什麼? – arved
這只是測試哪部分代碼出錯了 – user1423793