I hope that in this post, I can get people's opinions on best practices for the interface between JSF pages and backing beans.
One thing that I never can settle on is the structure of my backing beans. Furthermore, I have never found a good article on the subject (correct me if I'm wrong).
What properties belong on which backing beans? When is it appropriate to add more properties to a given bean as opposed to creating a new bean and adding the properties onto it? For simple applications, does it make sense to just have a single backing bean for the whole page, considering the complexity involved with injecting one bean into another? Should the backing bean contain any actual business logic, or should it strictly contain data?
Feel free to answer these questions and any others that may come up.
As for reducing coupling between the JSF page and the backing bean, I never allow the JSF page to access any backing bean property's properties. For example, I never allow something such as:
<h:outputText value="#{myBean.anObject.anObjectProperty}" />
I always require something like:
<h:outputText value="#{myBean.theObjectProperty}" />
with a backing bean value of:
public String getTheObjectProperty()
{
return anObject.getAnObjectProperty();
}
When I loop over a collection, I use a wrapper class to avoid drilling down into an object in a data table, for instance.
In general, this approach feels "right" to me. It avoids any coupling between the view and the data. Please correct me if I'm wrong.
Edit: Maybe i'm wrong about this. It doesn't seem as if anyone else is in agreement with me.
Thanks in advance,
~Zack