File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes JSF and servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF and servlets" Watch "JSF and servlets" New topic

JSF and servlets

Charles Arminstice

Joined: Sep 12, 2007
Posts: 4
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.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

JSF and servlets work together just file. The only restriction is that since JSF is itself accomplished via a servlet and only one servlet can receive an HTTP request, you have the choice of using JSF or of using a user-defined servlet, but not both on the same request.

That's not the handicap it may seem to be. A servlet is basically a dispatching device, and it's not really a good idea to place business logic - business logic should go in independent classes, and independent classes can be used by both JSF and servlets or JSPs.

In the case of a JSF page that needs to feed into a servlet for a task like having the servlet generate an XLS file or a PDF, this can be done by taking advantage of the fact that the JSF beans are just POJOs and therefore they're equally visible to both.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: JSF and servlets
It's not a secret anymore!