I m working on an Spring application with lots of input forms. I d like to reuse the field length in the UI-form, validation and JPA annotations. Is there an elegant way to solve this. My solution at the moment is, to use constants to declare the length:
public class Person
{
public static final int FIRSTNAME_LENGTH = 25;
@Column(length=FIRSTNAME_LENGTH)
private String firstName;
...
}
and then reuse the constant in the Validator and the Jsp
...
<form:input path="firstName"
maxlength="<%= Integer.toString(Person.FIRSTNAME_LENGTH) %>"/>
...
which is pretty verbose.
Is there any more elegant solution to this problem?