RESOLVIDO - Diferença <h:selectOneMenu para <p:selectOneMenu

Alo pessoal

Tenho um selecOneMenu com o e funciona perfeitamente, mas quando mudo para o selectOneMenu do primefaces ele não funciona. Fui so showcase da prime e não consegui. Peguei tambem alguns exemplos na net e nenhum consegui fazer funcionar.

XHTML

<h:outputLabel for="cmbCargo" value="#{msgs.lbUsuCargo}"/>
<h:selectOneMenu id="cmbCargo" converter="cargoConverter" value="#{usuarioMNG.cargo}">
        <f:selectItems value="#{cargoMNG.listaSelectItem}" var ="vCargo" itemLabel="#{vCargo.nome}"/>
</h:selectOneMenu>
<p:message for="cmbCargo" showDetail="true"/>

Converter

package br.gov.dpu.jsf.converter;

import br.gov.dpu.jsf.mng.CargoMNG;
import br.gov.dpu.jpa.bean.Cargo;
import javax.el.ValueExpression;
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.faces.convert.FacesConverter;

@FacesConverter(value = "cargoConverter")
public class CargoConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        FacesContext ctx = FacesContext.getCurrentInstance();
        ValueExpression vExp = ctx.getApplication().getExpressionFactory().createValueExpression(ctx.getELContext(), "#{cargoMNG}", CargoMNG.class);
        CargoMNG cargoMNG = (CargoMNG) vExp.getValue(ctx.getELContext());
        Cargo car = cargoMNG.getCargo(Long.valueOf(value));
        if (car == null) {
            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Valor desconhecido", "Selecione um Cargo");
            throw new ConverterException(msg);
        }
        return car;
    }

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

CargoMNG

public List<SelectItem> getListaSelectItem() {
        List<SelectItem> lista = new ArrayList<SelectItem>();
        lista.add(new SelectItem(null, ""));
        for (Cargo car : dao.listaTodos()) {
            lista.add(new SelectItem(car, car.getNome()));
        }
        return lista;
    }

e o Bean

package br.gov.dpu.jpa.bean;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@Table(name = "cargo")
@NamedQuery(name = "Cargo.findAll", query = "select o from Cargo o order by o.nome")
public class Cargo implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Column(nullable = false, length = 50)
    private String nome;
    
    public String getNome() {
        return nome;
    }

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

    public Long getId() {
        return id;
    }

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

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

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 67 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }
}

lembrando que com o funciona beleza, mas quero usar o do Prime, ae que da o problema.

Alguem sabe a solução ou onde eu a encontro?

Olá!
Não cheguei a testar a versão 3.0 do PrimeFaces.
Mas meus orientados tentaram usar o p:selectOneMenu, mas também não obtiveram sucesso…
Por ser uma versão nova, talvez possa ter bugs ainda nesse componente.

Oi Andi,

Eis a solução… esqueci de postar no forum.

Funciona perfeitamente.

Meu erro era fazer o List ja que o primefaces pede Lista de um objeto e nao de select

XHTML

 <p:selectOneMenu id="cmbSetor" converter="setorConverter"
                                             value="#{usuarioMNG.setor}"
                                             style="width: 160px; height: 22px">
                                <f:selectItems value="#{setorMNG.listaSelectItem}" var ="vSetor"
                                               itemLabel="#{vSetor.nome}"
                                               itemValue="#{vSetor}"/>/>
</p:selectOneMenu>

MNG

public List<Cargo> getListaSelectItem() {
        List<Cargo> lista = new ArrayList<Cargo>();
        for (Cargo car : dao.listaTodos()) {
            lista.add(car);
        }
        return lista;
    }

converter

@FacesConverter(value = "cargoConverter")
public class CargoConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        FacesContext ctx = FacesContext.getCurrentInstance();
        ValueExpression vExp = ctx.getApplication().getExpressionFactory().createValueExpression(ctx.getELContext(), "#{cargoMNG}", CargoMNG.class);
        CargoMNG cargoMNG = (CargoMNG) vExp.getValue(ctx.getELContext());
        Cargo car = cargoMNG.getCargo(Long.valueOf(value));
        if (car == null) {
            FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Valor desconhecido", "Selecione um Cargo");
            throw new ConverterException(msg);
        }
        return car;
    }

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

Olá Gustavo!
Obrigada por passar a solução :lol: