Convert to AbstractEditPageBean

0

I created a domain class whose primary key is composed. I created a convert for the primary key class.

I registered the convert in faces-config , in addition to using the @FacesConverter annotation in the converter class, with ID in value , and forClass . But it seems that the editing page inherited from AbstractEditPageBean is not being able to find my converter, returning the following message:

  

"You need to create a FacesConverter for the" ... "class.

Do I need to do anything else, register in another location?

Comments:

  • In other places the converter is working normally, as in the list screen
  • Demoiselle archetype jsf-jpa 2.4.2
asked by anonymous 06.04.2015 / 15:13

3 answers

0

It seems like the getIdConverter() method of the AbstractEditPageBean class is not getting my convert back. I managed to solve it in the way below, but I still think it is not ideal.

I overwritten the getId() method on my edit page, where id is the parameter:

@Override
public MyCompositeKey getId() {
    MyConverter converter = new MyConverter();
    return (MyCompositeKey) converter.getAsObject(null, null, id.getValue());
}

Fernando

    
06.04.2015 / 20:47
0

I have been able to solve it differently, I do not know if it is the ideal. I made a copy of the abstract class AbstractEditPageBean , calling it AbstractEditPageBeanConverter and adding the convert class to the ID:

public abstract class AbstractEditPageBeanConverter <T, I, C> extends...
    ...
    private Class<C> converterForIdClass;
    ...
    protected Class<C> getConverterForIdClass() {
        if (this.converterForIdClass == null) {
            this.converterForIdClass = Reflections.getGenericTypeArgument(this.getClass(), 2);
        }
        return this.converterForIdClass;
    }
    ...
    @Override
    @SuppressWarnings("unchecked")
    public I getId() {
        Converter converter;
        try {
            converter = (Converter) getConverterForIdClass().newInstance();
        ...
        return (I) converter.getAsObject(facesContext, facesContext.getViewRoot(), id.getValue());
    }
    ...
}
    
06.04.2015 / 22:15
0

I discovered what I was doing that did not work.

For the entity class, I wrote the convert with value and forClass :

@FacesConverter(value="ConversorMinhaClasse", forClass=MinhaClasse.class)  
public class MinhaClasseConverter implements Converter...

Now for the composite key class, if using value does not work, then I wrote the convert without this:

@FacesConverter(forClass=MinhaChaveComposta.class)  
public class MinhaChaveCompostaConverter implements Converter
    
25.06.2015 / 15:22