Search code examples
jpatapestry

Preparing a JPA entity for use by a HTML form


Say I want to populate a JPA entity using values supplied by a user through a web application form (Tapestry for that matter).

What is the best way to obtain the "blank" instance of the JPA entity that is going to be bound to the form fields?

As of now I just use the new operator as follows in my Tapestry class:

childminderAccount = new ChildminderAccount();

Is this not a somewhat a crude way of doing it? Is there a better way?


Solution

  • Nope, that's the best way to do it. One of the advantages of JPA (over old EJB Persistence) is that it is a "lighter" framework. One of it's lightnesses is the fact that it now works woth POJOs (or Java Beans). I would recommend however to take a look at Java's new validation API which is very lightweight as well, and it can insure that a JPA Bean is correctly populated from your form (like no non-nullable fields set to null, empty id field etc):

    http://www.hibernate.org/subprojects/validator.html