Convert to Abstracteditpagebean

Asked

Viewed 94 times

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 the faces-config, in addition to using the annotation @FacesConverter in the converter class with the ID in the value, and the forClass. But it seems that the edit page inherited from AbstractEditPageBean is unable to find my converter by returning the following message:

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

Do I need to do anything else, register somewhere else?

Remarks:

  • In other locations the convert is working normally, as in the list screen
  • Archetype Demoiselle jsf-jpa 2.4.2

3 answers

0

It seems that the method getIdConverter() of the Abstracteditpagebean class is failing to recover my converter. I was able to solve it in the following way, but I still don’t think it’s ideal.

I overwrote the method getId() on my editing page, where id is the parameter:

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

Fernando

0

I managed to solve otherwise, I don’t know if it is ideal. I made a copy of the abstract class AbstractEditPageBean, calling her AbstractEditPageBeanConverter and adding the class of convert for 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());
    }
    ...
}

0

I found out what I was doing that didn’t work.

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

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

Already for the composite key class, if using the value doesn’t work, so I wrote down the convert without it:

@FacesConverter(forClass=MinhaChaveComposta.class)  
public class MinhaChaveCompostaConverter implements Converter

Browser other questions tagged

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