Error validation pattern

Hello, I must be doing something wrong with my test Vaadin site.

I need to create a “wizard” that collects data in 3 pages; I created my application, added fields of the first page to my mainLayout and called validate() on each field in the “Next” button listener.
Fields are required and I set a requiredError for each of them: it looks like no error message is displayed when I leave them empty. What’s wrong?

Secondly: what pattern do you suggest to step to second page? Should I remove all fields and add the new ones? Or group them in different panel and make them visible and invisible?

Thank you!

Where do you expect the error message to be displayed? The validate() will just throw an EmptyValueException (extends InvalidValueException).

How about something like this:

public class Page1View extends VerticalLayout {
public Page1View() {
// create fields here

public void doValidation() throws InvalidValueException{
// validate fields here

then where ever you are doing page switching, just call

public void buttonClick(ClickEvent event) {
try {
    someLayout.replaceComponent(page1, new Page2View()); // or something like this
} catch (InvalidValueException e) {
    // do something

Also I recommend
Wizards for Vaadin add-on

Here’s a simple example of how to manually show error messages for components when not using a Form. For more details, see the chapter about
Error Handling
in the Book of Vaadin.

public void init() {
	Window mainWindow = new Window("Playground Application");

	final TextField tf = new TextField();

	Button button = new Button("Click", new ClickListener() {

		public void buttonClick(ClickEvent event) {
			try {
			} catch (EmptyValueException e) {
				tf.setComponentError(new UserError("Field may not be null"));

As Johannes suggested, you could take a look at the Wizard add-on in the directory.