Time for action – validating user input

We can run a TestSet instance only if the user selects one. Follow these steps to add a proper validation:

  1. Implement your initButton method to match this code:
    private void initButton() {
      button.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
          if(isValid()) {
            runSelectedTest();
          }
        }
      });
    }
  2. Now implement your validate method. Here is how we validate:
    public boolean isValid() { combo.setComponentError(null); textField.setComponentError(null); boolean isValid = true; if(combo.getValue() == null) { combo.setComponentError( new UserError("Select a test from the list.")); isValid = false; } if(textField.getValue().toString().isEmpty()) { textField.setComponentError(new UserError( ...

Get Vaadin 7 UI Design By Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.