It's quite possible to access the information stored in annotations. In fact, this is their main purpose: storing meta information on a class/ method/ field.
Here is an example of how to access the length stored in a @Column annotation:
import javax.persistence.Column;
import javax.persistence.Entity;
@Entity
public class Person {
@Column(length=30)
private String firstName;
public static void main(String[] args) throws SecurityException, NoSuchFieldException {
Object person = new Person();
//find out length
System.out.println(person.getClass().getDeclaredField("firstName").getAnnotation(Column.class).length());
}
}
You should be able to create some custom tag or bean to extract this info generically.
It's not difficult to create your own annotations. You could consider creating one that specifies which fields are to be included on the form, how they should be rendered, description, etc. Than you could create a generic form. Then again you may not like to mix domain and presentation.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…