I'm working on a simple Vaadin form where I want the text entered in a TextField to appear in a Label after the user clicks on a Button.
Here's the code snippet:
package com.example;
import javax.servlet.annotation.WebServlet;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
public class TestForm extends UI {
@WebServlet(value = "/TestForm", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = TestForm.class)
public static class Servlet extends VaadinServlet {
}
private TextField textField;
private Label label;
private Button button;
@Override
protected void init(VaadinRequest request) {
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);
textField = new TextField("Enter text");
label = new Label();
button = new Button("Click");
button.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
label.setValue(textField.getValue());
}
});
layout.addComponent(textField);
layout.addComponent(button);
layout.addComponent(label);
}
}
However, when I click on the Button, nothing happens with the label and the web browser displays an error message:
Communication problem Take note of any unsaved data, and click here to continue. (SyntaxError) stack: eval@[native code] Jda BR Zc Xc line: 340: Unexpected token '<' - Original JSON-text: html>
What am I doing wrong?