below in the jsr303 validations
public RegisterUserCommand(final String userName, final String password, final String email) {
super();
this.userName = userName;
this.password = password;
this.email = email;
Contract.requireValid(this);
}
The above generates a generic string concatenated exception with multiple errors concatenated with the contraintvaiolationexception on the Contract. What if we want to validate using jsr (I know that the command needs to be pre-validated), however if you are creating a webservice or api and want all the server side containment to a thin non-intelligent client, can the stuctural validation be handled as step 1 before moving the command forward? If the command is not returning a hash of results for these types of errors with their app messages (maybe even locale-aware), then there could be a lot of app intelligence on the thin client. Ideally a quick structural validation similar to the one in address-book with spring-mvc Entity validation binding from ContactsController.java
public String formNewAddressSubmit(@ModelAttribute(“address”) @Valid AddressEntry address, BindingResult bindingResult) {
if (!bindingResult.hasErrors()) {
RegisterAddressCommand command = new RegisterAddressCommand();
command.setAddressType(address.getAddressType());
command.setCity(address.getCity());
command.setContactId(address.getIdentifier());
command.setStreetAndNumber(address.getStreetAndNumber());
command.setZipCode(address.getZipCode());
commandBus.dispatch(command);
…
This above uses a interesting way with hibernate validator to validate an incoming request server side with the query model of the Entity before moving the command forward, however in client controller code leveraging spring-mvc for the binding of the errors to the client.
So how do we get the same objective if without duplication of structural validation logic? assuming a webservice client or a rest api client, which is completely dumb.
Maybe the addressbook example serializing the AddressEntry Entity object to the command and the validation happening there with an exception which populates the errors?
Any ideas??
Thanks
return “redirect:/contacts/” + address.getIdentifier();
}