Vaadin and AppEngine, I can't get it to work

Hi,

I’m starting with Vaadin, which has been great so far. Very easy to use, with great results. We’re looking at using it for internal apps mainly although I would like to use it for some more public-facing things, hence…

I’ve been trying to get something working on Google AppEngine and am having trouble, so could do with some help.

Here is my application.

public class MyApplication extends Application implements Button.ClickListener {
    private static final Logger LOG = Logger.getLogger(MyApplication.class.getName());

    private VerticalLayout layout;
    private SampleForm sampleForm;

    public MyApplication() {
        super();
    }

    public void init() {
        Window window = new Window();

        sampleForm = new SampleForm();
        layout = new VerticalLayout();
        layout.addComponent(sampleForm);

        addShowButton();

        window.addComponent(layout);

        setMainWindow(window);
        window.getContent().setSizeFull();
    }

    private void addShowButton() {
        Button b = new Button("Show");
        b.setDescription("Click to show");
        b.addListener(this);
        layout.addComponent(b);
    }

    public void buttonClick(Button.ClickEvent event) {
        if (!sampleForm.isValid()) {
            layout.getWindow().showNotification("Sample Form Doesn't validate");
        } else {
            String customerID = sampleForm.getCustomerID();
            layout.getWindow().showNotification("Sample Form shows " + customerID);
        }
        LOG.info("Form has value <" + sampleForm.getCustomerID() + "> for customer id");
    }

    private static class SampleForm extends Form {
        private static final String CUSTOMER_ID = "CustomerID";
        private static final String DEFAULT_CAPTION = "Basic Data";

        public SampleForm() {
            setInvalidCommitted(false);
            getLayout().setMargin(true, true, true, true);
            setCaption(DEFAULT_CAPTION);
            setImmediate(true);
            addField(CUSTOMER_ID, customerIDField());

        }

        public String getCustomerID() {
            return (String) getItemProperty(CUSTOMER_ID).getValue();
        }

        private TextField customerIDField() {
            TextField val = new TextField(CUSTOMER_ID);
            val.setRequired(true);
            val.addValidator(new RegexpValidator("\\s*\\d+-3-\\d+\\s*", true,
                    "Customer ID is of the form customerID-3-index"));
            return val;
        }
    }

This works fine on my local machine, but doesn’t work at all on AppEngine.

Its up on http://vmtestapp.appspot.com to look at.

If you type “58-3-5” into the field and hit show it should validate, but doesn’t. If you hit refresh the field state is lost and you see sync errors.

AppEngine is very aggressive at activating and passivating sessions so perhaps its a serialization issue? I put some code in to check and it seemed to serialize/deserialize the application object on every request.

I’ve put the project code at http://dl.dropbox.com/u/17994/vaadintest.zip. I’m using Guice but I got the same problems when i removed it so don’t think that is the problem.

Any help would be gratefully received, as this has stopped me stone dead.

Tim

You need to use GAEApplicationServlet when running in Google App Engine. From what I saw you currently extend AbstractApplicationServlet.

That’s done the trick, thanks. I completely missed the different servlet…

Tim