I have been thinking about this for a long time and have not yet figured out how to organize my beans / classes in a JSF project for presentation level. Obviously, many factors come into play, but I would like to discuss. Here is my current thought:
Consider the base JSF (still stuck on JSF 1.xx here, unfortunately) an application that contains a view page (view data) and an edit page (add, update, delete data). Here is how I could organize a project:
BackingBean Scope Request:
- View related materials (saving status, visualization of logic, etc.). Material that is required only on one request.
- Actions, action listeners, and value change listeners. If applicable to multiple views, they can be split into their own file.
BackingBean session coverage:
- All that should remain around more than one request. Database data, SelectItems, etc.
- This bean is entered into the bean request and stores instances of any data objects
Data Objects:
- It seems there is no point in making data objects in beans, so they are stored separately. It will be such things as User, Book, Car, any object that you are going to display on the page. An object may also contain helper presentation methods, such as getFormattedName (), etc.
DAO:
- A bean that handles all interactions with the business logic layer. It loads bean data and prepares views, etc. I usually do this with a class of public static methods.
Converters, validators:
This seems to be all that is needed in your average JSF application. I read this: http://java.dzone.com/articles/making-distinctions-between , and also the answers here: Support for the JSF bean structure (best practices) , but I never felt like we had a complete picture. BalusC's answer was helpful, but didn't seem to cover the full application. Let me know your thoughts!
source share