As part of a project that I am working on I need to either find or develop coding conventions and best practices for developing JSF. So far a Google search for such has been largely unsuccessful. Are there any industry recognized coding conventions and best practices for JSF and if so, where can I find them? [ April 10, 2006: Message edited by: Linda Walters ]
<a href="http://labryssystems.net/pblog/index.php" target="_blank" rel="nofollow">Javaville Gazette</a><br />Non-cooperation with evil is a duty. -- Mahatma Gandhi
Wow, that's a doozy of a question. I don't know of any official standards and any that may be out there I'd question. More or less JSF is JSP's and Java code. So most coding standards should fall into the same realm as coding up JSP's and your typical Java coding conventions.
As far as JSF specific methods, it would be interesting to see who comes up with what. I've read both Core JSF and JSF In Action and neither get too heavy into "this should be done this way" which seems fairly typical for any Java API/Framework. There are always 10 ways to do the exact same thing and 10 people will swear by 10 completely different methodologies. It's the nature of the beast I suppose.
I have my own views on how certain things should be done, but they are by no means standards worthy, mostly because it's just preference. For example, I try to have as little markup in the JSP even if that means more java code in the backing bean. Other people adhere to less Java code and more markup.
This thread should be interesting. Be sure and let us know if you find anything else.
Gerardo Tasistro
Ranch Hand
Joined: Feb 08, 2005
Posts: 362
posted
0
Here are my two cents worth:
keep HTML code within JSF tags (<f:verbatim> , that will make it easy to move blocks of JSF stuff to include files and recycle later
master panelGrid and panelGroup, understand the usage of row and column styles and classes
adding to the previous post, dynamic panels with rows rendered based on a flag will require a dynamic list of stylesClasses so you'll need a method for that that returns a string list of styles names. Obviously a poorly sincronized code will lead to unexpected visual results
beware convert errors from objects to element values and back, gets tricky, look at the issues with selectOneMenus in this thread
I test the program with JUnit and the managed bean+input data to the getters and setters of the items on the view
I test the view with a dummy bean for input validation and conversion, just to make sure all works (lists, options, I/O), see above beware convert errors. JSF is just too lengthy to build and deploy and too full of gotchas as you start to work with it. Test every single tag and make sure you undertand it before building this huge page full of JasperExceptions or who knows what else. Also see point 3 on styleClasses.
put the two previous points together and pray
careful with the redirect flag in the navigation rule and user reload of the page, it can trick you. I've moved mostly to a redirect setting, but the default (at least MyEclipse's editor default) is no redirect.