completeMethod primeFaces is returned the Id where it should return name

0

I'm creating a form where I have neighborhood address name etc, and for that, I'm using prime Faces.

<p:outputLabel value="Nome" for="nome" />        
<p:autoComplete id="nome" size="60"
            value="#{cadastroFuncionarioBean.funcionario.pessoa}"
            completeMethod="#{cadastroFuncionarioBean.pesquisarNomes}" 
            itemLabel="#{pessoa.nome}" />

When I create the auto completeness it works perfectly, but when I do a search it returns me the person ID instead of the name.

I think the problem is in my PersonConverter.java, which as can be seen below is returning the id.

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.model.Pessoa;
import br.com.repository.Pessoas;

@FacesConverter(forClass = Pessoa.class)
public class PessoaConverter implements Converter {
    @Inject // funciona graças ao OmniFaces
    private Pessoas pessoas;

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        Pessoa retorno = null;
        if (value != null) {
            retorno = this.pessoas.porId(new Long(value));
        }
        return retorno;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if (value != null) {
        return ((Pessoa) value).getId().toString();
        }
        return null;
    }


}

Well, so, come the question really need to create a class convertNome, convertEndereco and convertBairro etc ... to each attribute of my person class as below.

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotEmpty;

@Entity
@Table(name = "pessoa")
public class Pessoa implements Serializable {
    private static final long serialVersionUID = 1L;
    Long id;

    private String nome;
    private String endereco;
    private String numero;
    private String complemento;
    private String bairro;
    private String cidade;
    private String estado;
    private String cep;


    @Id
    @GeneratedValue
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @NotEmpty
    @Size(max = 100)
    @Column(length = 100, nullable = false)
    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    @NotEmpty
    @Size(max = 100)
    @Column(length = 100, nullable = false)
    public String getEndereco() {
        return endereco;
    }

    public void setEndereco(String endereco) {
        this.endereco = endereco;
    }

    @NotEmpty
    @Size(max = 6)
    @Column(length = 6, nullable = false)
    public String getNumero() {
        return numero;
    }

    public void setNumero(String numero) {
        this.numero = numero;
    }


    //@NotEmpty
    @Size(max = 50)
    @Column(length = 50, nullable = false)
    public String getComplemento() {
        return complemento;
    }

    public void setComplemento(String complemento) {
        this.complemento = complemento;
    }

    @NotEmpty
    @Size(max = 30)
    @Column(length = 30, nullable = false)
    public String getBairro() {
        return bairro;
    }

    public void setBairro(String bairro) {
        this.bairro = bairro;
    }

    @NotEmpty
    @Size(max = 30)
    @Column(length = 30, nullable = false)
    public String getCidade() {
        return cidade;
    }

    public void setCidade(String cidade) {
        this.cidade = cidade;
    }

    @NotEmpty
    @Size(max = 2)
    @Column(length = 2, nullable = false)
    public String getEstado() {
        return estado;
    }

    public void setEstado(String estado) {
        this.estado = estado;
    }

    @NotEmpty
    @Size(max = 9)
    @Column(length = 9, nullable = false)
    public String getCep() {
        return cep;
    }

    public void setCep(String cep) {
        this.cep = cep;
    }


    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Pessoa other = (Pessoa) obj;
        if (id == null) {
            if (other.id != null)
                return false;
        } else if (!id.equals(other.id))
            return false;
        return true;
    }
}

Or is there a more elegant way to do this?

    
asked by anonymous 25.07.2016 / 16:56

0 answers