Hi,

I'm currently migrating from GWT 1.4 to 2.0 and am changing
from Listener to Handler from class to class. I've found the
following problem with a TextBox/Label-combination. Here
some code:

// this part is inside a method building a row in a table,
// index is the row-number being passed as parameter
final Label receiverLabel = new Label(recipientAddress);
final TextBox receiverValue = new TextBox();

receiverValue.addKeyPressHandler(new KeyPressHandler() {
public void onKeyPress(KeyPressEvent event) {
  switch(event.getCharCode()){
    case KeyCodes.KEY_ENTER:{
      GWT.log("key enter pressed, confirm");
      confirmParameterValue(receiverLabel, receiverValue, index);
      break;
    }
    case KeyCodes.KEY_ESCAPE:{
      GWT.log("key cancel pressed, cancelling");
      cancelParameterValue(receiverLabel, receiverValue, index);
      break;
    }
  }
}
});

receiverValue.addBlurHandler(new BlurHandler() {
  public void onBlur(BlurEvent sender) {
    GWT.log("on blur, confirming");
    confirmParameterValue(receiverLabel, receiverValue, index);
  }
});

private void confirmParameterValue(Label oldName, TextBox newName, int index){
  GWT.log("confirm " + newName.getText()  + " to " + oldName.getText());
  oldName.setText(newName.getText());
  GWT.log("confirmed name is now " + oldName.getText());
  // call cancel to perform the change in the GUI, values
  // are equal now, so this is not a problem
  cancelParameterValue(oldName, newName, index);
}

private void cancelParameterValue(Label oldName, TextBox newName, int index){
  GWT.log("cancel " + newName.getText()  + " back to " + oldName.getText());
  newName.setText(oldName.getText());
  newName.setVisible(false);
  oldName.setVisible(true);
  GWT.log("cancelled name is now " + oldName.getText() + "/" + 
newName.getText());
}

In the plugin (I haven't tried it with a deployed application, yet)
I receive the following outputs in the message-pane, if I enter
"1" into the TextBox, pressing enter, reenter "1_2"
in that TextBox and press ESCAPE:

00:25:59,713  [INFO] key enter pressed, confirm
00:25:59,718  [INFO] confirm 1 to
00:25:59,719  [INFO] confirmed name is now 1
00:25:59,729  [INFO] cancel 1 back to 1
00:25:59,736  [INFO] cancelled name is now 1/1
00:26:01,410  [INFO] on blur, confirming
00:26:01,415  [INFO] confirm 1 to 1
00:26:01,420  [INFO] confirmed name is now 1
00:26:01,421  [INFO] cancel 1 back to 1
00:26:01,426  [INFO] cancelled name is now 1/1

00:26:07,089  [INFO] key cancel pressed, cancelling
00:26:07,089  [INFO] cancel 1_2 back to 1
00:26:07,097  [INFO] cancelled name is now 1/1
00:26:08,849  [INFO] on blur, confirming
00:26:08,853  [INFO] confirm 1_2 to 1
00:26:08,853  [INFO] confirmed name is now 1_2
00:26:08,853  [INFO] cancel 1_2 back to 1_2
00:26:08,854  [INFO] cancelled name is now 1_2/1_2

Messages 00:26:07,089 and 00:26:08,853 confuse me. Both are
working with the same instances of TextBox and Label, so why
is there still the value "1_2" in newName in onBlur after
being set to "1" in cancelParameterValue?

The whole thing worked in GWT 1.4 using onLostFocus
and onKeyPressed. Of course I can introduce a boolean
being checked in onBlur but if this is a bug, it would
be a very ugly workaround for something that should be
fixed in my eyes.

Used version: GWT SDK Bundle 2.0.3.v201002191036 running
the Browser plugin for Firefox 3.6.2


Best regards, Lothar

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to