• Post Reply Bookmark Topic Watch Topic
  • New Topic

Data errors vs. prefetch for JSP

 
Allan Halme
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kinds of solutions are applied to providing all required data for JSPs? The two options I see (at least in my situation) are --
(1) Have a "root" domain object in the session, so that the JSP can fetch it (e.g. Project), and then can generate its HTML by pulling the attributes it needs straight from the Project object. E.g., project.getName(), project.getSites() and thus perhaps in a loop site[i].getName(), site[i].getAddress(), site[i].getContact() and then contact.getName(), etc.
However, if these domain objects are connected to a persistent store, any of the getters, say the last one, could fail -- then the JSP will have executed for nothing and either the HTML rendering falters half-way or someone higher has to catch the failure and redirect to an error JSP or whatever.
(2) Instead of having the JSP pull the data it needs, ultimately perhaps all the way from persisten store, have its handler/action prefetch all the data its gonna need and store it in the session. Thus any low-level failures are caught right away, and all the JSP's data resides in the session, ready for the JSP.
Thoughts?
 
Rick DeBay
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're discussing the Dispatcher View vs Front Controller pattern. The knowledgable consensus comes down in favor of Front Controller.
See <cite>Core J2EE Patterns [Alur, Crupi, Malks]</cite> for definitions of these patterns, or just Google on the terms.
Rick DeBay
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Approach (2) is more along the lines of my druthers, but...
If the data is only pertinent to the JSP, storing the data in the session is a bit of overkill. It's much more common for the controller to fetch the data and tack it onto the request for the JSP to display.
Data that is needed across a session is appropriate for storing in the session, as data common across the web application is appropriate for storing in the application (servlet) context.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!