Custom Tags And Data Access

B

Ben Jessel

Hi,

I've been brought up with the purist mantra ( ahh...bless ), of only
using custom tags for presentation logic, and not for data access;

I remember seeing why when I had a iteration loop in a web-page with a
nested custom tag that accessed a database on each iteration over a
2000 steps ; I ran out of DB connections very quickly.

So since then, I've been using Struts / Servlets to load my data, and
then custom tags to format the data.

However, I've got two issues where I can't do this:

1) I want my home page to be called index.jsp. I want to show a list
of the 10 most recently posted messages to a forum. The only way I can
see how to do this is through Data Access via a JavaBean / Custom Tag.
Doing this via struts would require a start page such as
myWebsite/loadIndexPageData.do, forwarding to index.jsp - not a nice
url for your start page....

2) I have a list of categories in the database, which are self
referencing ( eg, cat->subcat1->subcat2->subcat(n) . So each has a
parent / child ID ( if I was using oracle I could use a
connectByPath... ).

I want to display data on the page as a nested list of these
categories:

My Super Category
|
|-> category ( from the category table )
|
|-> sub category ( from the category table )

As we can have an arbitary depth, I have to keep querying the database
until some kind of end condition is reached ( select * from categoty
where parent_id = X returns null ). Under each category, I may have
news items / articles etc, that are related. Eg, news, articles tables
will have a category_id...

Am I best to do get the categories / subcategories with iteration /
recursion in a custom tag, or to try and do this in a servlet - with
some type of Type bean that has parents and children that gets
returned to the page? My instinct is to go with servlets, but this
could get quite complex.

Also, whatever I do, I'll need some way of printing out all the forums
/ articles etc for a given sub-category. So I'll have something in the
iteration that does:

<logic:iterate collection="category" id="=curr_cat_id">
<mytag:getArticlesForCategory curr_category_id="<%=curr_cat_id%>"
id="article"/>
<logic:iterate/>

where getArticlesForCategory will have to form DB access within a
page, which I'm concerned about..

Any ideas of how to approach this?

Thanks

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top