1
resposta

selectOneMenu, falha no converter

Estou tentando recuperar o valor selecionado em um selectOneMenu, ele carrega direitinho com os valores, mas na hora de enviar ao bean aparece a mensagem "Erro de validação, O valor não é valido"

Segue o converter

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if (value != null && !value.equals("")) {
            car = aa.getCarById(Integer.parseInt(value) );
        }else {
            return null;
        }            
        return car;
    }


    @Override
    public String getAsString(FacesContext context, UIComponent component, Object object) {
         if (object == null) {
           return null;
         }    
         return ( (ControllerCars) object).toString() ;
       }    
    }

O mapeamento

//classe carro
    @ManyToOne
    @JoinColumn(name = "acessos_id")
    private ControllerAccess proprietario;


//classe propietario
    @OneToMany(mappedBy = "proprietario")
    private List<ControllerCars> veiculos;

O selectOneMenu

<p:selectOneMenu id="veiculo" class="form-control"
value="#{diary.caroosTeste}" converter="#{convertercar}" >
<f:selectItems value="#{diary.access.veiculos}"
  var="veiculo" itemValue="#{veiculo}"
  itemLabel="#{veiculo.marca} - #{veiculo.modelo}" />        
</p:selectOneMenu>

Qualquer ajuda sera bem vinda.

1 resposta

Oi Deivide, tudo bem?

Como está sua classe ControllerCars? Ela é uma entidade que implementa Serializable e sobreescreve o método hashCode() ?

O seu converter está com @FacesConverter(value = "convertercar") ?

Nesse trecho:

value="#{diary.caroosTeste}"

caroosTeste é um objeto do tipo ControllerCars?