Error or Bug? Hi, I have an error appearing on the eclipse console, on the registration screen the form writes perfectly, everything ok, but the console points:
java.lang.NumberFormatException: For input string: "Selecione"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at br.com.bb.uds.rotinas.controller.converter.PessoaConverter.getAsObject(PessoaConverter.java:18)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:171)
at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectOneValue(MenuRenderer.java:202)
My convert:
@FacesConverter(value = "pessoaConverter", forClass = Pessoa.class)
public class PessoaConverter implements Converter {
@Override
public Object getAsObject(FacesContext arg0, UIComponent arg1, String id) {
try {
PessoaServices pessoaServices = new PessoaServices();
return pessoaServices.obterEntidade(Long.valueOf(id));
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
@Override
public String getAsString(FacesContext arg0, UIComponent arg1, Object pessoa) {
if (pessoa.toString().equals("-1")) {
return null;
}
return ((Pessoa) pessoa).getId().toString();
}
}
XHTML where I use convert :
<!-- RESPONSAVEL -->
<h:outputLabel for="responsavel" value="Responsável"
styleClass="panelGridGerenciar" />
<p:selectOneMenu id="responsavel"
value="#{rotinasBean.rotina.pessoaResponsavel}" required="true"
requiredMessage="Selecione um responsável"
converter="pessoaConverter">
<p:ajax event="change" listener="#{rotinasBean.changeSubstituto}"
update="substituto" />
<f:selectItem itemLabel="Selecione" itemValue="-1" />
<f:selectItems var="_responsavel"
value="#{rotinasBean.selectResponsaveis}"
itemValue="#{_responsavel}" itemLabel="#{_responsavel.nome}" />
</p:selectOneMenu>
The console points to this line of error.
return pessoaServices.obterEntidade(Long.valueOf(id));
I do not know if it's really a bug or a bug, thanks in advance.