我有一个在我的实体上使用侦听器的 Jspresso 应用程序。问题是当我修改监听的属性时没有调用这个监听器。
这是侦听器定义:
public WagonTransportOrderExtension(final WagonTransportOrder component) {
PropertyChangeListener nbVehiclesListener = new PropertyChangeListener() {
@SuppressWarnings("unchecked")
public void propertyChange(PropertyChangeEvent evt) {
Integer nbVehicles = 0;
Integer oldValue = getComponent().getNbVehiclesPersisted();
for(LoadDetail detail : (Collection<LoadDetail>)evt.getNewValue()) {
nbVehicles += detail.getQuantity();
}
getComponent().setNbVehiclesPersisted(nbVehicles);
getComponent().firePropertyChange(
WagonTransportOrder.NB_VEHICLES_PERSISTED, oldValue, nbVehicles);
}
};
getComponent().addPropertyChangeListener(
WagonTransportOrder.LOAD_DETAILS, nbVehiclesListener);
}
这个实体的一个简单用例:
WagonTransportOrder wagonTransportOrder = createEntityInstance(WagonTransportOrder)
Vehicle vehicle = createEntityInstance(Vehicle)
vehicle.setVin("00000000000000000")
save(vehicle)
wagonTransportOrder.addToLoadDetails(vehicle)
在调试它时,该addToLoadDetails()
指令不会导致侦听器的调用。