If I have a class hierarchy like the following. It is based on the Bakery application and I am trying to adapt it.
I have a Payment Entity which includes a list of PaymentLineItems and I want to display them in a web component using dom-repeat template.
I have
@MappedSuperclass
public abstract class AbstractEntity implements Serializable {
@Id
@GeneratedValue
private Long id;
A class which uses the abstract class
@Entity
public class Payment extends AbstractEntity implements Serializable {
/** A logger for this class. */
.....
private List<PaymentLineItem> lineItems;
public List<PaymentLineItem> getLineItems() {
return lineItems;
}
And the PaymentLineItem also extends the AbstractEntity so it too has a Long id field.
public class PaymentLineItem extends AbstractEntity {
/** A line item number. */
I want to have a view like the following that displays a payment with its list of payment line items
public class CheckoutView extends PolymerTemplate<CheckoutModel>
implements HasLogger {
public interface CheckoutModel extends TemplateModel {
@Encode(value= LongToStringEncoder.class, path="payment.id")
void setPayments(List<Payment> payments);
}
I get the following because I don’t seem to be able to tell Vaadin to encode the “id” field. There is an “id” field in both the Payment and PaymentLineItem classes (from AbstractEntity) which is a Long and which needs to be encoded to a String but it is not working for me and I get the following.
There was an exception while trying to navigate to 'checkout' with the exception message 'Error creating bean with name 'com.SyberNet.billpay.ui.views.users.checkout.CheckoutView': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.SyberNet.billpay.ui.views.users.checkout.CheckoutView]
: Constructor threw exception; nested exception is com.vaadin.flow.templatemodel.InvalidTemplateModelException: Type 'class java.lang.Long' is not supported. Used in class 'AbstractEntity' with property named 'id'. Supported types are: double, String, int, Double, boolean, Integer, Boolean, Beans and Lists of Beans.. Use @Encode annotation to convert the type to a supported type.'
How do I specify the path to the “id” field in both Payment and also in the list of payment line items that is returned by a method in Payment called getLineItems() so that it is encoded as a string.