tags:

views:

2695

answers:

6

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.

+8  A: 

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.

Rowan
+6  A: 

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....

Tim Howland
+1 on that. JSF without Facelets just feels broken.
Damo
+9  A: 

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:

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))
David Waters
A: 

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.

fnCzar
A: 

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

+1  A: 
  • 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.
Erik Itland