[
https://hibernate.onjira.com/browse/HV-585?page=com.atlassian.jira.plugin...
]
Gunther Schmidl commented on HV-585:
------------------------------------
Right, I'm saying it would be nice to have the option of a guaranteed order. As an
example, in my current application, I add five constraint violations at once if specific
conditions are not met, so you would get something like:
Invalid password: {numMin} of the following conditions must be met:
At least {numLC} lowercase characters.
At least {numUC} uppercase characters.
At least {numSC} special characters.
At least {numNC} digits.
I am adding these constraints using
validatorContext.buildConstraintViolationWithTemplate(message).addConstraintViolation(),
which puts the items in an ArrayList. Later, they are moved to a HashSet, and then to a
String[] array for display.
So the question is: why keep order intact when adding constraints (ArrayList) and
displaying constraints (String[]), but not inbetween?
Obviously, the HashSet randomly jumbles the order of messages, which then make no sense.
Using a LinkedHashSet in the implementation instead would keep the order intact.
As it is, I am currently implementing my own <custom:errors> JSP tag which sorts the
messages by a number prefix it then removes, which is of course suboptimal.
Order of validation messages is lost
------------------------------------
Key: HV-585
URL:
https://hibernate.onjira.com/browse/HV-585
Project: Hibernate Validator
Issue Type: Improvement
Components: engine
Affects Versions: 4.3.0.Final
Environment: ---
Reporter: Gunther Schmidl
Labels: hibernate, validation
When adding validation messages, they are stored in an ArrayList. Later on, they are
transferred to a HashSet, and finally to a String[] array. Naturally, putting them in a
HashSet screws up the order of the messages, which may be important (for example, I have a
"header" error message I wish to display first). Please consider changing the
HashSet to a LinkedHashSet.
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira