Avoid this common JSF mistake

Posted by: Dan Allen on 05/01/2008

Don't access the database in a method that feeds a UIData component! (e.g. <h:dataTable>) I see this mistake being made all the time. It's bad advice and just plain bad practice. Don't do it!

What most people don't realize (perhaps because they are not watching the SQL log output in their ORM tool) is that value expressions are resolved more than once during the JSF life cycle--usually a lot more than once. Every time the value expression that feeds the UIData component is resolved in this scenario, your database takes a hit. On top of that, the result set could change depending on what you are retrieving and how you are doing it.

I will present a brief example and then show how to fix it using Seam.

Continue Reading...


be the first to rate this blog

About Dan Allen

Dan Allen

Dan Allen is a member of the Seam and Web Beans project teams at JBoss by Red Hat, author of Seam in Action and a frequent speaker at major industry conferences such as JavaOne, Devoxx, TSSJS, Jazoon and JSFOne. Dan is known for his passionate work, with nearly a decade of development experience using technologies that include Java frameworks (Seam, JSF, EJB3, Hibernate, Spring, Struts), testing frameworks (JUnit, TestNG), JavaScript and DOM scripting, CSS and page layouts, Maven 2, Ant, Groovy, and many others.

Quickly after graduating from college, Dan became captivated by the world of free and open source software (FOSS). His involvment in FOSS helped him transition into the software development industry. He soon discovered the combination of Linux and the Java EE platform to be the ideal blend on which to build his professional career. In his search for a robust Web framework, Dan discovered JBoss Seam, which was quickly granted this most coveted spot in his development toolbox. The rest, as they say, is history. Dan is also a dedicated open source and Linux advocate and blogs about his experiences regularly. You can keep up with his discoveries by subscribing to his blog at http://mojavelinux.com.

More About Dan »

NFJS, the Magazine

December Issue Now Available
  • Hibernate Performance Tuning, Part 2
    by Scott Leberknight
  • Virtualization for Development
    by Pratik Patel
  • Emergent Design & Evolutionary Architecture
    by Neal Ford
  • Writing Secure Code with ESAPI
    by Ken Sipe
Learn More »