This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF and servlets

 
Charles Arminstice
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic