3
Error or Bug? Well I have an error appearing in the eclipse console, on the registration screen the form records 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 in which I use the 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 that line of error.
return pessoaServices.obterEntidade(Long.valueOf(id));
I don’t know if it’s really a mistake or a bug.
You have already debugged to see the values that are passed to the variables?
– Macario1983