Table - BeanItemContainer Enum Question

Hi, I am a newbie of vaadin and i am testing a PoC case. My question is related with table component. I have a table which uses a BeanItemContainer. I have several columns in the table and one of them is actually a integer status field in the db. What i want is to show the enum string value of this column and not the actual underlying integer db value. Here are the code snippets of the related parts.

Table and bean item part: container

Collection<Entity> entities = entityService.listAllEntities();
BeanItemContainer<Entity> container = new BeanItemContainer<>(Entity.class, entities);
Table eTable = new Table();
eTable.setContainerDataSource(container);
eTable.setVisibleColumns("name", "entityType", "address", "email", "contactInfo", "phone");

Related Bean (Entity):

[code]
@javax.persistence.Entity
@Table(name = “entity”)
@XmlRootElement
public class Entity implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "entity_id")
private Integer entityId;

@Basic(optional = false)
@NotNull
@Column(name = "entity_type")
private int entityType;

@Basic(optional = false)
@NotNull
@Size(min = 1, max = 2147483647)
@Column(name = "name")
private String name;

@Size(max = 2147483647)
@Column(name = "address")
private String address;

// @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]

+(?:\.[a-z0-9!#$%&'+/=?^_`{|}~-]
+)
@(?:[a-z0-9]
(?:[a-z0-9-]
*[a-z0-9]
)?\.)+[a-z0-9]
(?:[a-z0-9-]
*[a-z0-9]
)?", message=“Invalid email”)//if the field contains email address consider using this annotation to enforce field validation
@Size(max = 2147483647)
@Column(name = “email”)
private String email;

@Size(max = 2147483647)
@Column(name = "contact_info")
private String contactInfo;

@Size(max = 2147483647)
@Column(name = "account1")
private String account1;

@Size(max = 2147483647)
@Column(name = "account2")
private String account2;

@Size(max = 2147483647)
@Column(name = "account3")
private String account3;

@Size(max = 2147483647)
@Column(name = "tax_number")
private String taxNumber;

// @Pattern(regexp="^\\(?(\\d{3})\\)?[- ]

?(\d{3})[- ]
?(\d{4})$", message=“Invalid phone/fax format, should be as xxx-xxx-xxxx”)//if the field contains phone or fax number consider using this annotation to enforce field validation
@Size(max = 2147483647)
@Column(name = “phone”)
private String phone;

public Entity() {
}

public Entity(Integer entityId) {
    this.entityId = entityId;
}

public Entity(Integer entityId, int entityType, String name) {
    this.entityId = entityId;
    this.entityType = entityType;
    this.name = name;
}

/* Getters and Setters ... */

@Override
public int hashCode() {
    int hash = 0;
    hash += (entityId != null ? entityId.hashCode() : 0);
    return hash;
}

@Override
public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof Entity)) {
        return false;
    }
    Entity other = (Entity) object;
    if ((this.entityId == null && other.entityId != null) || (this.entityId != null && !this.entityId.equals(other.entityId))) {
        return false;
    }
    return true;
}

@Override
public String toString() {
    return "com.intebu.pohats.domain.Entity[ entityId=" + entityId + " ]

";
}

}
[/code]Enum Class:

[code]
public enum EntityType {

CUSTOMER("EntityType_customer", 0), 
INSURED("EntityType_insured", 1),
INSURER("EntityType_insurer", 2),
REINSURER("EntityType_reinsurer", 3),
COINSURER("EntityType_coninsurer", 4),
FRONTING("EntityType_fronting", 5),
PERSON("EntityType_person", 6);

private final String typeName;
private final int id;

private EntityType(String tName, int tId){
    typeName = tName;
    id = tId;       
}

public String getTypeName() {
    return typeName;
}

public int getId() {
    return id;
}

public static EntityType getByEntityTypeName(final String tName) {
    EntityType result = null;
    for (EntityType entityType : values()) {
        if (entityType.getTypeName().equals(tName)) {
            result = entityType;
            break;
        }
    }
    return result;
}

}
[/code]Maybe this is asked before but for a newbie it is hard to find the correct search keywords.
Any help would be appreciated. Thanks.

Write a column generator.

        table.addGeneratedColumn("entityType", new ColumnGenerator() {
            
            @Override
            public Object generateCell(Table source, Object itemId, Object columnId) {
                if (columnId != null) {
                    Object value = source.getContainerProperty(itemId, columnId).getValue();
                    // convert to string or a component
                }
                return null;
            }
        });