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 ]
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!
Best, David Thompson, BSCS, PMP
Joined: Apr 03, 2006
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?
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.
Joined: Apr 03, 2006
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?