I am developing a threaded message board. Each message has an ID, a parentID
(if it is a reply) and a threadID. To display the children of the current
message (and their children, and so on), I have written the method below.
<%! public void showChildren(int p_id, int level, ResultSet r, JspWriter
out) {
try {
while (r.next()) {
for (int i=0; i<level; i++) {
out.print(" ");
}
if (r.getInt(6) == p_id) {
out.print("<a href=\"dis_display_new_code.jsp?ID=" +
r.getInt(8) +
"&t_id=" + r.getInt(7) + "\">" + r.getString(1) + "</a> by " +
r.getString(4) + "<br>");
showChildren(r.getInt(8), level+1, r, out);
}
}
} catch(NumberFormatException e) {
out.print(e);
} catch(SQLException e) {
out.print(e);
}
}
%>
The method is passed the ID of the current message and a ResultSet that
contains all the messages in the current thread. At the end of the while
loop, the method calls itself, passing the same ResultSet and the ID of the
current child (to find _it's_ children).
I am wary of using methods that call themselves, so I would like to know if
this approach is safe and if anyone can suggest a better way of doing this.
Thanks,
Paul
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html