I am working on a rewrite of the jobs-posting application at <http://trijug.org/jobs.jsp>. This is my first application using Struts. I'm trying to be a good MVC boy scout, separating the View (JSPs, tag libraries) from its Model (database and JavaBeans). But achieving this separation seems to necessitate extra coding and computation, unless I am overlooking something. I write for input.

Consider the question of how to deliver a set of job listings into the JSP which renders the listings. Each job listing occupies one record in the MySQL database. So somewhere the code will iterate through a ResultSet. With good MVC separation I suppose this iteration through the ResultSet would occur in the Model. With good MVC separation I suppose the View would never contain a statement like:
import java.sql.ResultSet


Have I got that right?

What seems required then is that the Model would iterate through the ResultSet, packaging the data probably into some Collection which will be passed to the View. The View then would have to iterate through this Collection in order to generate the needed HTML. As such we iterate through the list twice, once in the Model and once in the View.

Whereas in a simpler world it would be acceptable for the JSP which generates the HTML to be handed a ResultSet through which it would iterate. In this simpler world there would be only one iteration through the list. Interestingly, something like this is done in the sample application for the book _The Struts Framework_ by Sue Spielman. The book starts out with a chapter about MVC and separation. But the sample application has a custom tag -- part of the View -- which does all the work I would expect to see in the Model (all the java.sql, Connection, Statement, ResultSet stuff).

Am I learning a simple truth, that the benefit of separating responsibilities into tiers can be gained only by paying the cost of duplicate handling of data? Or is there something I'm missing?

Thank you,
Rich Hammer
Hillsborough

_______________________________________________
Juglist mailing list
[email protected]
http://trijug.org/mailman/listinfo/juglist_trijug.org

Reply via email to