Let’s say I have an entity with some persistent fields
@Column(name = "UNIT_PRICE")
protected BigDecimal unitPrice = BigDecimal.ZERO;
@Column(name = "AMOUNT")
protected BigDecimal amount = BigDecimal.ZERO;
and a transient field
@MetaProperty(related = {"amount", "unitPrice"})
public BigDecimal getSubtotalWithoutVat() {
return unitPrice.multiply(amount);
}
In the gui, i want the subtotal field to be updated when either amount or unitprice is edited. Preferable in an automatic fashion since the metadata information is there.
If not automatic, how to do this?
1 Like
krivopustov
(Konstantin Krivopustov)
August 27, 2018, 3:02pm
#2
Good question. You can do it if you override the propertyChanged()
method of the entity:
@Column(name = "UNIT_PRICE")
protected BigDecimal unitPrice = BigDecimal.ZERO;
@Column(name = "AMOUNT")
protected BigDecimal amount = BigDecimal.ZERO;
@MetaProperty(related = {"unitPrice", "amount"})
public BigDecimal getSubTotal() {
if (unitPrice == null || amount == null)
return BigDecimal.ZERO;
return unitPrice.multiply(amount);
}
@Override
protected void propertyChanged(String property, Object prev, Object curr) {
super.propertyChanged(property, prev, curr);
if (property.equals("unitPrice") || property.equals("amount")) {
super.propertyChanged("subTotal", BigDecimal.ZERO, getSubTotal());
}
}
Seems like it should be a default behavior of the framework, so I’ve created an issue .