Injected object but is null

Asked

Viewed 149 times

0

I have an object that is injected into my converter :

package br.com.pokemax.modelo.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.inject.Inject;

import br.com.pokemax.modelo.Geracao;
import br.com.pokemax.negocio.GeracaoDAO;

@FacesConverter(value = "geracaoConverter", forClass = Geracao.class)
public class GeracaoConverter implements Converter {

    @Inject
    GeracaoDAO dao;

    @Override
    public Object getAsObject(FacesContext arg0, UIComponent arg1, String value) {

        if (value != null) {
            try {
                Geracao geracao = dao.find(Long.parseLong(value));
                return geracao;
            } catch (Exception e) {
                e.printStackTrace();
                return e;
            }

        }
        return null;
    }

    @Override
    public String getAsString(FacesContext arg0, UIComponent arg1, Object object) {
        if (object != null) {
            return String.valueOf(((Geracao) object).getId());
        } else {
            return null;
        }
    }

}

I noticed that in other classes this dao is already instantiated, but in the convert it is null and because of this, my code does not pass the line:

Geracao geracao = dao.find(Long.parseLong(value));

And make the mistake NullPointer, someone knows how I can solve ?

Related question: Value is not being written to the bank

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.