I’m trying to block completely the input of a number in a field. I don’t want to invalidate the field, but rather not let the user type the number in the field at all.
I have tried to do this with an extension of TextField, but I don’t know if I’m doing something wrong or my concepts are wrong. The textField just behaves like a normal TextField.
I created two files: AlphaField and AlphaFieldConnector. The Connector class is in a folder called client in the same level as my Widgetset. When I compile the Widgetset I can see that is going through that file, but should I add anything else to MyWidgetSet.gwt.xml? I tried to add , but that doesn’t solve anything either.
Here is the code:
public class AlphaField extends AbstractExtension
{
public static void extend(TextField field)
{
new AlphaField().extend((AbstractClientConnector) field);
}
}
@Connect(AlphaField.class)
public class AlphaFieldConnector extends AbstractExtensionConnector
{
private static final long serialVersionUID = -737765038361894693L;
@Override protected void extend (ServerConnector target)
{
final VTextField textField = (VTextField) ((ComponentConnector) target).getWidget();
KeyPressHandler keyPressHandler = new KeyPressHandler()
{
@Override public void onKeyPress (KeyPressEvent event)
{
textField.cancelKey();
}
};
textField.addKeyPressHandler(keyPressHandler);
}
Just for simplicity and testing, what this should do (in my mind :P) is that when I type inside the extended component, nothing is written. This is how I use the component:
TextField textField = new TextField();
AlphaField.extend(textField);
addComponent(textField);
Any idea of why is this not working? Do I have the concept totally wrong?