I have done Java and JSP programming in the past, but I am new to Java Server Faces and want to know if there's a set of best practices for JSF development.
Some tips: Understand the JSF request lifecycle and where your various pieces of code fit in it. Especially find out why your model values will not be updated if there are validation errors.
Choose a tag library and then stick with it. Take your time to determine your needs and prototype different libraries. Mixing different taglibs may cause severe harm to your mental health.
Consider using facelets- it greatly simplifies the worst parts of JSF development. I'm doing a CMS-based JSF project now without facelets (after doing a project with it) and it feels like my left arm is missing....
I would strongly recommend getting someone experienced in JSF to lead your first project in JSF even if this means paying a contractor for 3 months. The JSF approach is very different to JSP. The way you approach and solve problems is very different.
Libraries
Consider the following libraries:
- Tomahawk http://myfaces.apache.org/tomahawk/index.html
- RichFaces http://www.jboss.org/jbossrichfaces/
- Shale http://shale.apache.org/
- Trinidad http://myfaces.apache.org/trinidad/index.html
- Spring
Architecture
Embrace MVC you need not only to know what this means but use it extensively.
There are two main patterens for assotiating controllers with the views
Dot Net Style, One Request controller per view
Every top level page has a request scoped controller (bean) all validation and actions of the page use this class. Also used for filtering and ordering the Model. The Model will be stored on a few session level contollers which will handle talking to the backend (EJBs, or persistance layer) these session controllers should be implementing the business logic and have no knowledge of JSF,HTML or any presentaion technology.
Controllers are session level
Design controllers based on your data model, nest them with in each other. (This post is getting too long so I wont go into the nuts and bolts of these).
Knowledge Required
Everyone:
- Life Cycle
- MDC
- Component based development
- Tags in h: and f:
At Least One Person:
- Creating Custom Components
- Limitations to JSF (back button, random navigation, etc)
- Debug 3rd party libaries (At least one person has to be comfertable breaking out the debugger and stepping into the implmentation of JSF (easiest with open source implementations like MyFaces))
I have been using the IBM implementation of JSf and have some comments. It is not a bad way to go but you have to commit to the IBM 'way-of-life'. They have written their own tag lib which extends the JSF standard. If you can manage to stay inside of Rational Application Developer (RAD) (which does not get updated THAT often), the integration is sometimes buggy but overall decent. Also the integration with WebSphere is pretty good. Unless your employer plays golf with IBM, I think it is better to stay as vanilla as possible.
I am not yet aware of a "Best Practice" for cross field / form level validation.
That is, JSF validation is currently orientated to single field validation. IMO it gets ugly when you look at complex cross field / form level validation.
Old but still looks acurate to me http://weblogs.java.net/blog/johnreynolds/archive/2004/07/improve_jsf_by_1.html
http://www.jroller.com/robwilliams/entry/jsf_multi_field_validation_not
- Add my vote for facelets. I've recently upgraded a project to use facelets, and it solves some big issues with jsf, specially giving you a decent template system right out of the box and letting you use standard html when it is appropriate, without wrapping it in "verbatim"-tags.
- RestFaces is a solution to the get/post problem that many people complain about. It's also well documented and easy to use.
- Don't use to many taglibs. It makes the job a lot harder when upgrading.
- SEAM collects many of the JSF best practices, but I haven't used it yet, so I can't really recommend it, just recommend you to take a look at it.