I have an Entity which is persisted and which provides data for rows in a Vaadin Grid. This part works.
I now want to display a boolean value as an Image. For this I added a getter to the entity. This part only works when the record has been persisted to the database recently, which I think means that the getter is persisted, which is not desired. For rows persisted to the database before introduction of the getter, the field stays blank in the vaadin grid due to enabledIcon property returning something empty.
I tried to disable this behavior by adding a @Transient annotation, but for some reason then the eureka client has errors, and it also does not help with the empty fields.
I am considering creating a new wrapper class by composition instead of inheritance, but then I have to create all these getters and setters manually which seems to me to be bad design.
Any answer is welcome, even the ones which tell me to go with a wrapper class by composition.
package com.xxx.bpspkpibpcheck.model;
import javax.persistence.Entity;
//import javax.persistence.Transient;
import com.xxx.common.model.KPI;
import com.vaadin.server.ThemeResource;
@Entity
public class KPIBusiness extends KPI {
private static final String IMAGES = "images/";
private static final String IMAGE_STATUS_RED = IMAGES + "LED_red_24.png";
private static final String IMAGE_STATUS_GREEN = IMAGES + "LED_green_24.png";
private static final String IMAGE_STATUS_GRAY = IMAGES + "LED_gray_24.png";
private ThemeResource redStatus = new ThemeResource(IMAGE_STATUS_RED);
private ThemeResource greenStatus = new ThemeResource(IMAGE_STATUS_GREEN);
private ThemeResource grayStatus = new ThemeResource(IMAGE_STATUS_GRAY);
//@Transient
//ThemeResource enabledIcon = greenStatus;
//@Transient
public ThemeResource getEnabledIcon()
{
return getEnabled() != 0 ? greenStatus : grayStatus;
}
}