Converter error for SelectManyCheckbox

0

I'm doing a Java web application and I ran into a problem with the converter to be used in selectmanycheckbox . The converter I made was this:

@FacesConverter(forClass = Indicacao.class)
public class IndicacaoConverter implements Converter {

    // @Inject
    private Procedimentos procedimentos;

    public IndicacaoConverter() {
        procedimentos = CDIServiceLocator.getBean(Procedimentos.class);
    }

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

        if (value != null) {
            Long id = new Long(value);
            retorno = procedimentos.porId(id);
        }

        return retorno;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if (value != null) {
            Indicacao indicacao = (Indicacao) value;
            return indicacao.getId() == null ? null : indicacao.getId().toString();
        }

        return "";
    }

}

The error ....

Caused by: java.lang.NumberFormatException: For input string: "com.odontoclinicas.clinicas.model.Indicacao@20"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Long.parseLong(Long.java:589)
    at java.lang.Long.<init>(Long.java:965)
    at com.odontoclinicas.clinicas.converter.IndicacaoConverter.getAsObject(IndicacaoConverter.java:27)
    at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValues(MenuRenderer.java:513)
    at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValuesForModel(MenuRenderer.java:337)
    at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectManyValue(MenuRenderer.java:128)
    at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:314)
    at org.primefaces.component.selectmanycheckbox.SelectManyCheckboxRenderer.getConvertedValue(SelectManyCheckboxRenderer.java:39)
    at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1034)
    at javax.faces.component.UIInput.validate(UIInput.java:964)
    at javax.faces.component.UIInput.executeValidate(UIInput.java:1237)
    at javax.faces.component.UIInput.processValidators(UIInput.java:702)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1220)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1220)
    at org.primefaces.util.ComponentUtils.processValidatorsOfFacetsAndChilds(ComponentUtils.java:313)
    at org.primefaces.component.api.UITabPanel.processValidators(UITabPanel.java:1073)
    at javax.faces.component.UIForm.processValidators(UIForm.java:253)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1220)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1220)
    at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1164)
    at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
    ... 53 more

You are indicating for this line ...

        Long id = new Long(value);
    
asked by anonymous 22.02.2018 / 19:43

0 answers