I am testing a few hours trying to understand why this code here is not working and I am getting a NullPointerExcepetion
. Can anyone notice something wrong?
import javax.enterprise.context.RequestScoped;
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.inject.Inject;
import javax.inject.Named;
import modelo.Condomino;
import repositorio.Condominos;
@Named
@RequestScoped
public class CondominoConverter implements Converter{
@Inject
private Condominos condominos;
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if(!value.equals(null)){
Condomino condomino = condominos.getCondominoPorCPF(value);
if (condomino == null)
throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR,"Não existe","Não existe"));
return condomino;
}
return null;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
if (null == value || !(value instanceof Condomino))
return null;
Condomino condomino = (Condomino) value;
return condomino.getCPF()==null?null:condomino.getCPF().toString();
}
}