When the user's input is validated on the server-side, we don't usually want to stop to the first error. Instead, we want to validate all the inputs and send back a list of the parameters that are invalid. In order to do that, we need an object that keeps track of the errors.
Here's an example of that object:
public class ErrorNotification { private List<String> errors = new ArrayList<>(); public void add(String message) { errors.add(message); } public boolean isEmpty() { return errors.isEmpty(); } public String toString() { return errors.stream() .collect(Collectors.joining(", ")); } }
Here's a snippet of code that shows how the notification object is actually used:
ErrorNotification errorObj = validator.validate(request); if (errorObj.isEmpty()) // Notify the client about the errors
Copyright © 2013 Welcome to the website of Davis Fiore. All Rights Reserved.