Validation

Displaying Validation Messages

By default linkki provides no UI element for displaying validation messages returned by a ValidationService. In order to display these messages a custom UI component has to be created along with a BindingManager. The BindingManager must override its updateMessages method that gets called after validation. A common pattern here is to use a Consumer<MessageList> as an argument to the BindingManager to decouple it from the actual custom UI component (which implements Consumer<MessageList>).

public class RegistrationBindingManager extends DefaultBindingManager {

    private final Consumer<MessageList> displayMessagesConsumer;

    public RegistrationBindingManager(RegistrationValidationService registrationValidationService,
            Consumer<MessageList> displayMessagesConsumer) {
        super(registrationValidationService);
        this.displayMessagesConsumer = displayMessagesConsumer;
    }

    @Override
    protected void updateMessages(MessageList messages) {
        super.updateMessages(messages);
        this.displayMessagesConsumer.accept(messages);
    }
}

Usage:

		validationService = new RegistrationValidationService(registrationPmo);
		bindingManager = new RegistrationBindingManager(validationService, ml -> messagesPanel.updateMessages(ml));