If have an table with entity, in this case account booking items. If you double-click on one item, an edit dialog is displayed. The edit dialog has an pickerField to choose the category (manually).
For the convenience of of the dialog, i check in the onBeforeShow(…) event the database for an matching category and if found I update the booking entity and the pickerField. The booking item is changed and when i close the dialog the new category setting is commited. But the pickerfield is not showing the new value.
The pickerField is only updated if i commit the entity. But this is not the solution. When the user presses the cancel button on the dialog, the changes must be canceld as well?
Any idea how to update the pickerfield?.
Here ist the example code:
@Subscribe
public void onBeforeShow(BeforeShowEvent event) {
Booking booking = getEditedEntity();
// now account is set, the picker field is empty
if (getEditedEntity().getAccount() == null) {
// get an account that matches the criteria
Account ac = bookingUtility.calculateAccountMatch(booking.getAmount(), booking.getReceiverIBAN(), booking.getUsage());
if (ac != null) {
// load the account with all needed attributes. Otherwise we get an exception!
ac = accountUtility.findAccount(ac.getName());
if (ac != null) {
// merge the entity
dataContext.merge(ac);
// set the new account value to the booking item
booking.setAccount(ac);
// try to update the pickerfield (no effect)
accountField.setValue(ac);
// try to validate that field (no effect)
accountField.validate();
// if the line is uncommented, the changes are reflected but the entity is already commitet
//dataManager.commit(booking);
}
}
}
bookingDl.load();
}
!Very interessting is, that he underlying table the changes on the entity instance immediatly shows