Error in converter for Selectmanycheckbox

Asked

Viewed 74 times

0

I am making a Java web application and came across a problem in 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 mistake....

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

It’s pointing to that line...

        Long id = new Long(value);
  • Is Indicacao.class implemented Serializable? Not using @Component in converter? Have tried using Long.valueOf(String) to get the ID?

  • Can resolve using value in class convert and calling on page.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.