我使用 jpa 和 jsf 进行开发。我没有放置所有代码,因为它非常大,我在为 netebeans 7.2 生成的代码中有 NullPointException。我认为 netbeans 正在犯错误,但我无法修复它。
@FacesConverter(forClass = MaterialEntrada.class)
public static class MaterialEntradaControllerConverter implements Converter {
public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
if (value == null || value.length() == 0) {
return null;
}
MaterialEntradaController controller = (MaterialEntradaController) facesContext.getApplication().getELResolver().
getValue(facesContext.getELContext(), null, "materialEntradaController");
return controller.ejbFacade.find(getKey(value));
}
java.lang.Integer getKey(String value) {
java.lang.Integer key;
key = Integer.valueOf(value);
return key;
}
String getStringKey(java.lang.Integer value) {
StringBuffer sb = new StringBuffer();
sb.append(value);
return sb.toString();
}
public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
if (object == null) {
return null;
}
if (object instanceof MaterialEntrada) {
MaterialEntrada o = (MaterialEntrada) object;
return getStringKey(o.getId());
} else {
throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: " + MaterialEntrada.class.getName());
}
}
}
该错误是由以下行引起的:
return controller.ejbFacade.find(getKey(value));
ejbFacate 为空,但控制器不为空。