I know you can easily (and almost without any effort) validate a form with the following controller:
But now I want to execute the same validation in the following method:
I know that seems a bit weird. But because data can be saved as in written to the database (even if there are validation errors) it's a functional requirement to show possible validation errors when the form is initially requested.
After some google research I have found a solution which seems to work very well after initial testing.
According to the Spring reference you can configure a DataBinder programatically. So you can set a validator and validate the target using this validator. This gives you a BindingResult (containing possible validation errors). Then you have to simply add that BindingResult instance as an attribute to the model (using the correct name) and you can access the errors in the JSP using errors-tag. A deeper look into the source code of the errors-tag reveals the name of the attribute we must use (and it's really easy: BindingResult.MODEL_KEY_PREFIX + modelName)
So combining all this information in the read-method results in the following code with same (similar) behavior with the update-method using the @Valid annotation