Tuesday, December 31, 2013

JSF Best Practices

Here I am documenting some best practices can be followed during JSF project development.

Open Source Components

  1. Use myfaces or Sun RI. It doesn’t matter which one you use because both comes from Sun. Sun offers myfaces through open-source community.
  2. Use richfaces to get rich look quicker. Click here to go to demo site.
  3. Use facelets to avoid compilation time and better code readability.


  1. Use eclipse latest version
  2. Use richfaces eclipse plugin. It offers Visual Page Editor for Richfaces, JSF, and HTML / CSS.
  3. Use Tomcat instead of JBoss to avoid server restart for each changes.

Naming Convention

  1. Keep resource bundle name and xhtml name as same. Example SearchUsers.xhtml and SearchUsers.properties
  2. Suffix all the managed bean with “Bean” word, like SearchUsersBean.java
  3. Keep all the folder names in lower case.


  1. For bigger project it is better to extend all the default components, that gives flexibility and extensibility to add new features in future.
  2. Use components effectively like oops concept to minimize the coding and maximize the usage.
  3. To keep your application scalable, minimize creating managed beans in session scope. Many of them recommending session scope for managed beans to solve the JSF component state problem but it is a serious issue if you want to host your application in clustered environment.
  4. Use Map object to capture values for components created inside loop.
  5. Write a custom datetime converter and register with java.util.Date type to keep control of TimeZone and default date format. See here for more information.
  6. Customize default JSF error messages. See here.
  7. Use facelets layout feature to simulate Struts Tiles kind of behavior.
  8. Always use Wrapper classes instead of primitive types. If you use primitive data type passing empty values from the field will through exception.
  9. Use for simple page navigation, use to submit form and does validation too.
  10. Don’t hesitate to use simple HTML input controls where JSF doesn’t provide good solution. For example displaying radio button in datatable has issues when you fetch data from database. For these scenarios I prefer to use simple HTML controls.
  11. Use instead of rendered attribute for and . If you use rendered attribute sometime action may not be fired if the bean by default returns false.
  12. If you are using JSF1.2, use to execute all your page initialization stuffs like fetching data from database, creating error messages to be displayed.
  13. If you are using JSF1.2, use field specific custom error message wherever is required. Example:

    More information can be found here.
  14. Don’t use inside iterative tags like and see here to know the reason.

Work around for some common issues

  1. Add immediate=”true” for Cancel and Reset types of buttons to bypass validations. See here.
  2. One of the major missing feature in JSF is calling an action before page invocation. Here is the workaround.
  3. Here an work around solution explained to invoke an action from url.
  4. This link explains the difference between and
  5. If you need to redirect from navigation-case to URL with param which is a property of a managed bean. Here is the work around.
  6. EL expressions in JSF are executed multiple times for datatable and other iteration tags hence get method in managed bean might call multiple times. Either initialize your variables in action method or @PostConstruct method or follow lazy initializationRead here for more explanation.
  7. With JSF implementation submitting form with enter key will not invoke action method. Here is a custom component which will solve this problem.
add to del.icio.us :: Add to Blinkslist :: add to furl :: Digg it :: add to ma.gnolia :: Stumble It! :: add to simpy :: seed the vine ::  ::  :: TailRank :: post to facebook

Related Articles


oakleyses said...

louis vuitton handbags, oakley sunglasses, louboutin, longchamp outlet, nike shoes, louis vuitton outlet stores, chanel handbags, burberry outlet, prada outlet, jordan shoes, tiffany and co, michael kors outlet, tory burch outlet, louis vuitton outlet, longchamp handbags, nike free, true religion jeans, michael kors outlet, kate spade outlet, polo ralph lauren outlet, tiffany and co, prada handbags, polo ralph lauren outlet, michael kors outlet, michael kors outlet, longchamp handbags, oakley sunglasses, ray ban sunglasses, kate spade handbags, burberry outlet, louis vuitton outlet, louboutin outlet, louboutin, coach factory outlet, air max, air max, coach outlet, gucci outlet, christian louboutin shoes, michael kors outlet, coach purses, ray ban sunglasses, michael kors outlet, louis vuitton, coach outlet store online, true religion jeans, oakley sunglasses cheap

oakleyses said...

ralph lauren, lululemon, air max, hollister, north face, nike air max, polo lacoste, vanessa bruno, timberland, vans pas cher, louboutin, louis vuitton, oakley pas cher, air max pas cher, nike roshe run, air max, true religion outlet, barbour, sac longchamp, air force, hollister, sac louis vuitton, nike free, polo ralph lauren, nike trainers, louis vuitton uk, nike roshe, sac hermes, longchamp, michael kors, sac burberry, sac guess, mulberry, new balance pas cher, converse pas cher, sac louis vuitton, hogan outlet, nike tn, north face, true religion outlet, ray ban pas cher, michael kors, air jordan, nike blazer, nike free pas cher, michael kors pas cher, abercrombie and fitch, ray ban sunglasses

oakleyses said...

mac cosmetics, mont blanc, marc jacobs, canada goose outlet, nike huarache, vans shoes, soccer jerseys, hollister, giuseppe zanotti, beats by dre, abercrombie and fitch, longchamp, insanity workout, celine handbags, bottega veneta, ghd, nfl jerseys, north face outlet, chi flat iron, ugg boots, birkin bag, ugg australia, canada goose, herve leger, ugg pas cher, rolex watches, valentino shoes, canada goose uk, canada goose, ferragamo shoes, canada goose, ugg boots, uggs outlet, north face jackets, soccer shoes, asics running shoes, new balance shoes, p90x, lululemon outlet, canada goose jackets, mcm handbags, instyler, babyliss pro, ugg, wedding dresses, jimmy choo outlet, reebok outlet, nike roshe run

oakleyses said...

parajumpers, karen millen, air max, converse, pandora charms, moncler, louboutin, moncler, links of london, lancel, juicy couture outlet, oakley, hollister, pandora charms, supra shoes, thomas sabo, canada goose, gucci, wedding dresses, timberland boots, swarovski crystal, air max, coach outlet store online, moncler, ray ban, canada goose, moncler, ugg, louis vuitton, swarovski, hollister, montre homme, moncler, hollister clothing store, ralph lauren, rolex watches, moncler outlet, moncler, iphone 6 cases, baseball bats, juicy couture outlet, toms shoes, vans, pandora jewelry, ugg, converse shoes