Is it good programming style to mix JSF pages and navigation with entity persistence and Servlets?
From doing my "initial" research into it, it seems there are two different styles.
style 1 - using JSF with JSP pages and no pure servlet involved. Using backing beans to persist data.
style 2 - using JSP pages with Servlets and session beans and entity persistence classes.
Is this true? I see there are some ways to get JSF to work with servlets and entity persistence classes but it dosen't seem to be something JSF was naturally designed to do???
Then again, all this is from someone who just learned JSF last week so I could be wrong on the whole thing.
Well if I understand you question I would say you are smack in the middle of what I consider the missing piece / big issue in JSF - that being state management.
I will give you a recommendation that is not style 1 or 2. The first problem I think people get into when using JSF is that they make the backing bean the business model. After all thats what all the books and documentation seem to imply. You see this alot when people use session beans and/or entity persistence classes to be their backing beans. Don't do it.
In all most all cases my recommendation is to make sure all of your backing beans are POJO's. Backing beans are/should be tightly coupled with the JSF view and I like to call them view controllers. Use them to manage your web page (controller), not hold your business data (model), they are consumers and producers of business data (M-V-C).
Thus you have two forms of persistence. First you need to determine how you will persist business data. This is where style 2 comes into play. You can use Entity persistence, session beans, ORM, JDBC, web services what ever to provide the interface to and if necessary persistence of your business data.
Second, if you are not developing a RESTful web page, which is my guess if you are using JSF, then you will also have the requirement to save the state of your web page (view). This would be especially true if your using an AJAX enabled component library like Apache Trinidad etc. This means that you will need to figure out how to persist those backing beans because they will represent your view state while the user is interacting with the web page.
JSF (specification/RI) does not provide much help. The choice for simple web applications is to persist your backing beans in the Web Session (Style 1). This works well but has considerable negative performance characteristics when working in distributed and/or high volume applications.
JBoss SEAM I think provides the best solution for this, or its the full JSF stack implement that provides a solution to this problem. Apache MyFaces "Orchestra" has recently been released and it provides persistence using Spring. There are a few other solutions out there or you could roll your own solution.
To be sucessful get a good solid base for JSF. JBoss SEAM or Oracle's Rich Client Faces (ADF) is my recommendation. If your using WebSphere then look at Apache Trinidad or some of the commercial offerings.
Hope that gives you something to think about.