Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

[Newbie] Model2 JSP + JDBC + JSTL forEach

843838May 9 2007 — edited May 10 2007
Hi,

This is my first post.

I'm running into a bit of brain failure over decoupling my JSP view page from the specifics of the JDBC the model uses.

I want to avoid the easy route of:
Controller
- interogates request as default main listing page.
- runs a JDBC query
- pops the ResultSet in the request
- forwards to the mainlisting.jsp view
JSP View
- Uses a scriplet to iterate and display the contents of the results set as an HTML table.

For a start I don't want to pass a ResultSet to the view page. I'd like to keep it completely ignorant of whether the application is using JDBC, XML or an EJB for it's data tier.

My first smart? idea was to write an adapter for ResultSet that provides a standard List (or similar) interface, taking data from the ResultSet and returning 'domain' value objects instead of Rows.

This presents a secondary problem however. In order to provide a List of beans around the result set I either need to copy the whole result set into an ArrayList or Vector on creation, or implement the entire List interface myself (<yawn>).

So I figured if it's that hard, it can't be the correct way.

Ultimately I'm after some type of Bean collection I can populate (or wrap around) a ResultSet, so that the following JSP will display the list.

<ul>
<c:forEach items="${theListOfItems}" var="item">
<li><c:out value="${item.foo}" /> - <c:out value="${item.bar}" /></li>
</c:forEach>
</ul>

Any pointers?

Cheers
Paul
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 7 2007
Added on May 9 2007
2 comments
119 views