EnumConverter in editable price lists

I wrote an EnumConverter described in Use enumeration in h: selectManyCheckbox ? Everything was fine until we found out that this converter does not work properly in editable files. The problem is that although I added the attribute inside the getAsString and getAsObject methods as follows:

@Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if (value instanceof Enum) {
            component.getAttributes().put(ATTRIBUTE_ENUM_TYPE, value.getClass());
            return ((Enum<?>) value).name();
        } else {
            throw new ConverterException(new FacesMessage("Value is not an enum: " + value.getClass()));
        }
    }
public Object getAsObject(FacesContext context, UIComponent component, String value) {
        Class<Enum> enumType = (Class<Enum>) component.getAttributes().get(ATTRIBUTE_ENUM_TYPE);
        try {
            return Enum.valueOf(enumType, value);
        } catch (IllegalArgumentException e) {
            throw new ConverterException(new FacesMessage("Value is not an enum of type: " + enumType));
        }
    }

In the last method ( getAsObject), it was not possible to find the attribute that I gave for the component attribute map. But from the pprimefaces of the editable datatable everything is fine. Is there a solution for this?

+5
source share
1 answer

, PrimeFaces datatable ( h:dataTable).

. .

getAsString():

context.getViewRoot().getViewMap().put(ATTRIBUTE_ENUM_TYPE + component.getId(), value.getClass());

getAsObject():

Class<Enum> enumType = (Class<Enum>) context.getViewRoot().getViewMap().get(ATTRIBUTE_ENUM_TYPE + component.getId());
+2

All Articles