I have model which represents an Employee. It has a field(let's say salary) which is also a model. So basically it is a nested property. I use Hibernate, JPAcontainer and MasterDetailEditor to visualize the data. So I extended the FieldFactory to be able to add a value change listener to the select field of salary. This change sets the tax field of the salary.
It is working, the data is updated in the DB but on the UI, not. I tried it with Push enabled, with pollInterval, none of them seems to work. I set the value through its property.
code:
This is in the overridden createField
final AbstractField field = (AbstractField) super.createField(container, itemId, propertyId, uiContext);
field.setImmediate(true);
field.addValueChangeListener(new Property.ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
final Item item = container.getItem(itemId);
final String salaryTypeSelectorValue =
item.getItemProperty(propertyName).getValue().toString() != null ? item.getItemProperty(propertyName).getValue()
.toString() : REGULAR;
if (REGULAR.equals(salaryTypeSelectorValue)) {
final SalaryHistory salaryHistory = ((JPAContainer<SalaryHistory>) container).getItem(itemId).getEntity();
JPAContainer<SalaryHistory> salaryHistoryContainer = (JPAContainer<SalaryHistory>) container;
salaryHistoryContainer.getItem(itemId).getItemProperty("socialTax").setValue(new BigDecimal("28.5"));
}
}
});
return field;
Update
I managed to achieve what I want, maybe it is a bit hacky, because I had to put a tiny logic into the salary model: In the setter of salary type I set the tax too and the UI updates immediately.