Oct 22nd, 2008, 11:37 AM
Getting error message from ValidationException
I am using the org.springframework.batch.item.validator.SpringVal idator along with org.springmodules.validation.valang.ValangValidato r.
This is as shown in the spring batch tutorial of validating errors.
I am able to do validation successfully. But I have problem in getting the error messages. I get a org.springframework.batch.item.validator.Validatio nException and then when i try to do e.getMessage(), I am not getting the error messages in a friendly way, I am getting it something like this
Validation failed for com.sample.example.model.VariableField@35c41b:
Field error in object 'item' on field 'variableDataValue': rejected value ; codes [variableDataValue.item.variableDataValue,variableD ataValue.variableDataValue,variableDataValue.java. lang.String,variableDataValue]; arguments ; default message [variable.data.value.required]
The value i am expecting is just the key "variable.data.value.required"
Is there any way to get only the keys?
Nov 25th, 2009, 04:30 AM
User Friendly Message from Valang Exception
Has anyone got a solution to this? I'm in exactly the same position so would appreciate any response.
Nov 25th, 2009, 04:46 AM
If you raise a JIRA we can put a BindException in as the cause of the ValidationException. Would that work?
Nov 25th, 2009, 04:55 AM
Yes I could pick up the cause of the exception and I'm guessing that as this is a BindException it will give me access to the user friendly messages thrown by Valang via the errors collection? If you could just confirm it will do this, I'll raise the JIRA.
Nov 25th, 2009, 05:05 AM
I had to write some custom code to extract the exact key.
Nov 25th, 2009, 08:11 AM
Correct. The workaround for now is to simply write your own version of SpringValidator that does this (it's only a few lines).
Originally Posted by JustinB