转换错误设置值“for'null converter'

时间:2015-03-10 13:29:31

标签: jsf primefaces converter jsf-2.2 selectonemenu

我正在尝试使用转换器,但是我收到了这个错误:

conversion error setting value " for 'null converter'

我不知道如何纠正这个问题。我在堆栈上读了一些错误但没有解决。有什么帮助吗?

@FacesConverter(forClass = Plataforma.class)
public class PlataformaConverter implements Converter {

private Plataformas plataformas;

public PlataformaConverter() {
    plataformas = CDIServiceLocator.getBean(Plataformas.class);
}

@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
    Plataforma retorno = null;

    if (value != null && !"".equals(value)) {

        Long id = new Long(value);
        retorno = plataformas.porId(id);
    }

    return retorno;
}

@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
    if (value != null) {
        System.out.println("aa"+((Plataforma) value).getId().toString());
        return ((Plataforma) value).getId().toString();
    }

    return "";
}

}

实体:

@Entity
@Table(name = "plataforma")
public class Plataforma implements Serializable {

private static final long serialVersionUID = 1L;

private Long id;
private String nome;

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

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

@NotBlank
@Size(max = 80)
@Column(nullable = false, length = 60)
public String getNome() {
    return nome;
}

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


@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;
    Plataforma other = (Plataforma) obj;
    if (id == null) {
        if (other.id != null)
            return false;
    } else if (!id.equals(other.id))
        return false;
    return true;
}

}

XHTML:

<p:outputLabel value="Plataforma" for="plataforma"/>
                <p:selectOneMenu id="plataforma" value="#{cadastroJogoBean.jogo.plataforma}">
                    <f:selectItem itemLabel="Selecione a plataforma"/>
                    <f:selectItems value="#{cadastroPlataformaBean.listaPlataformas}" var="plataforma"
                        itemValue="#{plataforma}" itemLabel="#{plataforma.nome}" />
                </p:selectOneMenu>

0 个答案:

没有答案