Let's say you validate your Car object with javax.validation.Validator in Hibernate Validator, and you get constraint violations for several fields in Car. A user has tried to submit the Car in an HTML form, and therefore these violations should be displayed to the user as messages associated with the relevant input fields, say "The car's weight can not be 0 kg" would be a tooltip to the field 'weight', which could also be coloured red.
If the member variable that was violated happened to be called weight in the Java code, it wouldn't be a problem to find the correct input field to attach the message to. Does anyone have a good strategy for making sure that the correct field names are used in forms, without using reflection? So that, for instance, an input element for a car's weight always has <input name="weight">? Is it possible to annotate a member with a string and then use that string as the name attribute for the input tag?
Brgds Trond
|