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

Architecture question with JSF

Ryan Day
Ranch Hand

Joined: Apr 03, 2006
Posts: 87
I'm building my first JSF web app, and I'm trying to get my hands around my architecture. The purpose of the web app is basically to update and display information from my database - nothing fancy.

The model consists of MySQL tables mapped to business objects (POJOs) through Hibernate. Then there are business service classes that receive a contract, validate it, then perform inserts, updates, or selects using the Hibernate session. The services generally return a business object, or List of business objects.

If I were using Struts, I would interact with these business services within the action classes.

Q: What are the pieces necessary to tie these services to the JSF servlet (controller) and JSF/JSP (view)? I think it has something to do with backing beans, but I'm not sure exactly where those fit.

I have been reading some good JSF resources, but they are a little fuzzy in this area.
[ March 14, 2008: Message edited by: Ryan Day ]

David Thompson

Joined: Mar 26, 2006
Posts: 4
What Is a JavaServer Faces Application?
What is a JavaServer Faces Application?
For the most part, a JavaServer Faces application is like any other Java web application. A typical JavaServer Faces application includes the following pieces:

* A set of JSP pages (although you are not limited to using JSP pages as your presentation technology)
* A set of backing beans, which are JavaBeans components that define properties and functions for UI components on a page
* An application configuration resource file, which defines page navigation rules and configures beans and other custom objects, such as custom components
* A deployment descriptor (a web.xml file)
* Possibly a set of custom objects created by the application developer. These objects might include custom components, validators, converters, or listeners.
* A set of custom tags for representing custom objects on the page

A JavaServer Faces application that includes JSP pages also uses the standard tag libraries defined by JavaServer Faces technology for representing UI components and other objects on the page.

I use NetBeans 6.0.1, which automatically creates all of the above. I have heard of hard-core programmers that insist on hand-coding all this information - if you are in that group, you got my respect!

David Thompson, BSCS, PMP
Ryan Day
Ranch Hand

Joined: Apr 03, 2006
Posts: 87
Mmmm, not necessarily trying to be hard core. But I'm looking for the loose coupling so I can swap JSF with another view technology later.

When NetBeans builds it for you, where does it put the data access code? Is it raw JDBC calls inside the backing beans? What kind of transaction management is it using?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17421

I normally have the backing beans injected with DAO or data service beans and leave the database logic out of the backing and business beans.

Spring can be combined with JSF very nicely. It handles the datasource bean construction and initialization and the construction and initialization of the DAO and data service beans. Then JSF can inject them into the backing beans.

It ups the application's overall parts count to do things like I do, but the individual parts are simpler and easier to unit-test without having to crank up the entire appserver.
[ March 18, 2008: Message edited by: Tim Holloway ]

An IDE is no substitute for an Intelligent Developer.
Ryan Day
Ranch Hand

Joined: Apr 03, 2006
Posts: 87
Thanks Tim. I had seen several examples with JSF and Spring, but since I don't know Spring I was hoping I could use straight Hibernate.

Do you think that would work, or would it be easier to go ahead and try to learn Spring and JSF together?
I agree. Here's the link:
subject: Architecture question with JSF
jQuery in Action, 3rd edition