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?