Please share your view on this kind of thing i’m currently testing out :
- Have an JPA entity inside my JSF managed bean
- Bind the entity’s properties to the JSF form elements like input text, combo, even datatable for the entity’s list of detail objects for example.
- Have the entity processed by a service object, meaning the entity object itself, and perhaps with some other simple variables / objects
- The service will do some basic validation or simple processes, and deliver the entity object to the DAO layer to be persisted
- And the JSF view will reflect on the detached entity
Is this kind of solution with passing the entities between tiers OK ?
Forgive me for my inexperience in this matter, since i was used to play with ‘variables’ in webapp (using map based formbean in struts 1), but i’ve read about transforming the entity objects into some other format, but i’m not sure what it is for ?
If the relations between entities are defined, we can bind it to JSF components, and therefore render based on and populate the entity’s properties.
Yes, this is perfectly fine and in fact the recommended way to do it nowadays.
This “transforming the entity objects into some other format” refers probably to the Data Transfer Object pattern, which was necessary in the bad old days before annotations, when entity classes usually had to inherit from some framework-specific base class, undergo bytecode manipulation or were implemented as proxy objects by an EJB container.
Such entity objects were either impossible to serialize or contained much more state than the actual entity data and therefore would waste a lot of space when serialized. So if you wanted to have a separate app server tier, you had to use the DTO pattern to have it communicate efficiently with the web tier.