Custom connector for extension never seems to trigger

I’m trying to write an extension for a TextField which would only allow input which matches the supplied regex pattern.

Using maven vaadin widget archetype I’ve made an extension, a connector and a shared state and compiled it. After extending a TextField and running the application using the ?debug mode (because devMode run configuration doesn’t seem to be working when clicking on run application my browser just claims that it can’t connect) shows RegexTextFieldConnector to be amongst all connectors. However when typing something in I don’t see RegexTextFieldConnector in the communication tab, only the TextFieldConnector, also no regex matching is performed.

Here’s my

package kingwidgets;

import kingwidgets.client.RegexTextFieldState;

import com.vaadin.server.AbstractExtension;
import com.vaadin.ui.TextField;

public class RegexTextField extends AbstractExtension {

private static final long serialVersionUID = -5543469313421213137L;

public RegexTextField(final String regex) {
    getState().regex = regex;

public void extend(TextField field) {

public void setRegex(final String regex) {
    getState().regex = regex;

public String getRegex() {
    return getState().regex;

protected RegexTextFieldState getState() {
    return (RegexTextFieldState)super.getState();


package kingwidgets.client;

import kingwidgets.RegexTextField;

import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ServerConnector;
import com.vaadin.client.annotations.OnStateChange;
import com.vaadin.client.extensions.AbstractExtensionConnector;
import com.vaadin.client.ui.VOverlay;
import com.vaadin.client.ui.VTextField;
import com.vaadin.shared.ui.Connect;

public class RegexTextFieldConnector extends AbstractExtensionConnector implements KeyPressHandler {

    private static final long serialVersionUID = -3067505126562949227L;

    public static final String CLASSNAME = "regextextfield";
    private VTextField textField;
    private String regex;
    protected void extend(ServerConnector target) {
        textField = (VTextField)((ComponentConnector) target).getWidget();
        regex = getState().regex;
    void updateRegex() {
        regex = getState().regex;

    public RegexTextFieldState getState() {
        return (RegexTextFieldState) super.getState();

    public void onKeyPress(KeyPressEvent event) {
        if (textField.isReadOnly() || !textField.isEnabled()) {
        int keyCode = event.getNativeEvent().getKeyCode();
        switch (keyCode) {
        case KeyCodes.KEY_LEFT:
        case KeyCodes.KEY_RIGHT:
        case KeyCodes.KEY_BACKSPACE:
        case KeyCodes.KEY_DELETE:
        case KeyCodes.KEY_TAB:
        case KeyCodes.KEY_UP:
        case KeyCodes.KEY_DOWN:
        case KeyCodes.KEY_SHIFT:
        if (!isValueValid(event)) {
    private boolean isValueValid(KeyPressEvent event) {
        String newText = afterKeyPress(event.getCharCode());        
        return newText.matches(regex);
    private String afterKeyPress(char charCode) {
        int index = textField.getCursorPos();
        String previousText = textField.getText();
        StringBuilder builder = new StringBuilder();
        builder.append(previousText.substring(0, index));
        if(textField.getSelectionLength() > 0) {
            builder.append(previousText.substring(index + textField.getSelectionLength(), previousText.length()));
        } else {
            builder.append(previousText.substring(index, previousText.length()));
        return builder.toString();



package kingwidgets.client;

import com.vaadin.shared.AbstractComponentState;
import com.vaadin.shared.annotations.DelegateToWidget;

public class RegexTextFieldState extends AbstractComponentState {

    private static final long serialVersionUID = 2527706691849194908L;
    public String regex = ".*";

And in the demo project here’s how it’s used.

package kingwidgets.demo;

import javax.servlet.annotation.WebServlet;

import kingwidgets.RegexTextField;

import com.vaadin.annotations.Theme;
import com.vaadin.annotations.Title;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;

@Title(“MyComponent Add-on Demo”)
public class DemoUI extends UI

@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = DemoUI.class, widgetset = "kingwidgets.demo.DemoWidgetSet")
public static class Servlet extends VaadinServlet {

protected void init(VaadinRequest request) {
    TextField textField = new TextField();
    RegexTextField regexTextField = new RegexTextField("[0-9]


    final VerticalLayout layout = new VerticalLayout();
    layout.setComponentAlignment(textField, Alignment.MIDDLE_CENTER);


[/code]Can anyone tell me what I’m doing wrong?