As the title said, I’m trying to convert every key typed in textfield to upper case using keypress handler.
I used extension to achieve this. See example code below:
import com.google.gwt.event.dom.client.*;
import com.vaadin.client.*;
import com.vaadin.client.ui.*;
import com.vaadin.client.extensions.*;
import com.vaadin.shared.ui.*;
@SuppressWarnings("serial")
@Connect(TextFieldUpCase.class)
public class TextFieldUpCaseConnector extends AbstractExtensionConnector {
@Override
protected void extend(ServerConnector target) {
final VTextField tf = (VTextField) ((ComponentConnector) target).getWidget();
tf.addKeyPressHandler(new KeyPressHandler() {
@Override
public void onKeyPress(KeyPressEvent event) {
char c = event.getCharCode();
if (Character.isLowerCase(c)) {
//I wish there is a method like below,
//or other ways to achieve the same result
//
//event.setCharCode(Character.toUpperCase(c));
}
}
});
}
}
There is no mechanism to intercept and altering the event like awt/swing do. So what the best solution for this problem? What can I use to achieve this?
Thanks.