Custom Tags And Data Access

Discussion in 'Java' started by Ben Jessel, Jul 10, 2003.

  1. Ben Jessel

    Ben Jessel Guest

    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
     
    Ben Jessel, Jul 10, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ranganath

    Custom Tags within Custom Tags.

    Ranganath, Oct 17, 2003, in forum: Java
    Replies:
    2
    Views:
    460
    Ranganath
    Oct 21, 2003
  2. Mike
    Replies:
    3
    Views:
    878
    Michael Borgwardt
    Jan 9, 2004
  3. A. Brinkmann
    Replies:
    2
    Views:
    1,077
    A. Brinkmann
    Apr 16, 2004
  4. koslows
    Replies:
    0
    Views:
    535
    koslows
    May 12, 2005
  5. Dave
    Replies:
    0
    Views:
    451
Loading...

Share This Page