SmartGWT Pro 2.3 Nightly build 2010-11-22
GWT 2.0.3
All browsers
I had a question around how SelectItem.getSelectedRecord() is supposed to work in combination with a ChangeHandler.The documentation on FormItem.addChangeHandler indicates that this handler is supposed to fire when an formItem is about to be changed but before the change has taken effect.
However, when adding a ChangeHandler to a SelectItem and then getting the selectedRecord inside the onChange method of that handler; I'm getting the record representing the new value in the SelectItem, not the old one.
The ChangeEvent itself does correctly return the old value in the getOldValue() method.
I was actually expecting to get the old record.
The functional requirement here is to add an email address to a recipient list when an order is assigned to a user. If the user is changed (from John Doe to Jane Doe, for instance); the previous added email address needs to be removed and the new one added.
I can work around this by doing getting the old user id from ChangeEvent.getOldValue() and then calling the datasource for that record; but it's an extra round-trip to the server...
GWT 2.0.3
All browsers
I had a question around how SelectItem.getSelectedRecord() is supposed to work in combination with a ChangeHandler.The documentation on FormItem.addChangeHandler indicates that this handler is supposed to fire when an formItem is about to be changed but before the change has taken effect.
However, when adding a ChangeHandler to a SelectItem and then getting the selectedRecord inside the onChange method of that handler; I'm getting the record representing the new value in the SelectItem, not the old one.
The ChangeEvent itself does correctly return the old value in the getOldValue() method.
Code:
SelectItem assignedTo = new SelectItem(UserField.FULL_NAME.getName(),UserField.FULL_NAME.getDisplayName()); /* Binding to handle changes to assignedTo, prior to the change taking effect */ HandlerRegistration assignedToPreChangeReg = assignedTo.addChangeHandler(new ChangeHandler(){ public void onChange(ChangeEvent event) { Log.debug("Pre change; old value: " + event.getOldValue() + "; new value: " + event.getValue()); Record oldAssignedTo = assignedTo.getSelectedRecord(); if(oldAssignedTo!= null && oldAssignedTo.getAttribute(UserField.EMAIL.getName())!= null) { String email = oldAssignedTo.getAttribute(UserField.EMAIL.getName()); Log.debug(this.getClass().getName() + " removing email address " + email +" from emailSelector"); emailSelector.removeEmail(email); } } });
The functional requirement here is to add an email address to a recipient list when an order is assigned to a user. If the user is changed (from John Doe to Jane Doe, for instance); the previous added email address needs to be removed and the new one added.
I can work around this by doing getting the old user id from ChangeEvent.getOldValue() and then calling the datasource for that record; but it's an extra round-trip to the server...
Comment