can’t change my object from a datatable - JSF with Primefaces

Asked

Viewed 100 times

1

I am retrieving my object from the datatable more at the time I redirect the datatable to another page to make a change, it shows an error. More takes the Object ID, I made a convert more unsuccessfully.

inserir a descrição da imagem aqui

my Converter

    package 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 dao.FabricanteDAO;
import modelo.Fabricante;

@FacesConverter(forClass = Fabricante.class)
public class FabricanteConverter implements Converter {

    @Inject
    private FabricanteDAO dao;

    public Object getAsObject(FacesContext arg0, UIComponent arg1, String value) {
        Fabricante fabricante = null;

        if (value != null) {
            fabricante = this.dao.buscarPeloCodigo(new Long(value));
        }

        return fabricante;
    }

    public String getAsString(FacesContext arg0, UIComponent arg1, Object valor) {

        if (valor != null) {
            Fabricante fabricante = (Fabricante) valor;
            return fabricante.getCodigo() == null ? null : fabricante.getCodigo().toString();
        }
        return "";
    }

}
  • There is Alura’s own forum, which may help you more quickly. Have you tried to post there?

1 answer

0


Change the notation @FacesConverter(forClass = Fabricante.class) by only:

@Named
public class FabricanteConverter implements Converter {

Package: javax.inject.Named;

  • Helped solve your problem?

  • Oops! solved yes. Thank you

Browser other questions tagged

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