I have a follow up question to the answer provided in below post
I know this is the practice used in JSF applications but, I fail to understand how the approach provided in that post eliminates tight coupling? Could someone please answer?
I have a follow up question to the answer provided in below post
I know this is the practice used in JSF applications but, I fail to understand how the approach provided in that post eliminates tight coupling? Could someone please answer?
The view is not really decoupled from it's underlying model as it's purpose it to display the internals of it's model.
However it makes a difference what this view model is and how it is attached to the view, and there are some gains in not backing the view by a persistent entity directly.
The backing bean often has to perform service calls or at least CRUD operations. Neither should be a concern of a JPA entity. The controller might also be useful for validation, access restrictions, caching etc.
A JPA entity usually does not control it's own lifecycle. Making it a backing bean would probably require the entity to control it's own transactions, at least to handle CRUD operations. This could work with an ActiveRecord implementation, but IMHO JPA entities do not lend themselves to the AR pattern too well.
In Java EE aplications, the DTO pattern is often used to decouple the persistence from the view, other external systems, or even from all layers of the application above the DAL. Entities are mapped to DTOs with more specific purposes, e.g. presenting a relevant selection of attributes from different entities to the frontend.
EDIT: If I have understood you issue correctly - you have an application where the getters of backing beans perform DB operations and cause your application to be slow. This is in fact a bad practice. The JSF lifecycle causes these getters to be called multiple times, each of the calls resulting in an unnecessary DB call.
The common practice is to fetch the complete data from DB after the backing bean was constructed and before data is displayed initially (effectively caching the data for the lifetime of the backing bean). The data should be refetched from DB only if the user explicitly refreshes it.
Please see this post for further explanation.