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!

Unordered List <UL> generation in JSP..

802523Sep 14 2008 — edited Nov 14 2008
Hello,

I am facing difficulties to generate subcategories in <UL> list.

I have a table with Menu Items :
cat_id | parent_id | title
-------------------------
1 | 0 | Solutions
2 | 0 | Products
3 | 1 | Web
4 | 1 | Development
5 | 2 | Softies
6 | 2 | PHP Book
-------------------------
I want to list get the out put in the form as below :
Solutions
  Web
  Development
Products
  Softies 
  PHP Book
What i have written is :
public  String generateMenuHTML(String id1) throws SQLException {
		pdb = new Pdb();
		String sql = "select ID,PARENT_ID,TITLE,URL,SORT,ICON from menu";
		rset = pdb.executeQuery(sql);
		
	    html = "<ul id='menu" + id1 + "'>";

	    while(rset.next())
	    {
			 id = rset.getString("ID");
			 parent_id = rset.getString("PARENT_ID");
			 title = rset.getString("TITLE");
			 sort = rset.getString("SORT");
			 url = rset.getString("URL");
			 icon = rset.getString("ICON");
	         html = html + "<li id='it" + id + "'><a href='" + url + "'>" + title + "</a>";
	         if (parent_id.equalsIgnoreCase("1"))
		      {
		    	  System.out.println(parent_id);
		    	  html = html +generateMenuHTML(id) ;

		      }
	      html = html + "</li>";
	    }	  
	    html = html + "</ul>";
		
        return html;
	}
Could you please help me how to retrieve sub categories and get the output in :

<ul>
<li>
<ul>
</ul>
</li>
</ul>

Kindly suggest me how to go about..

Thanks and Rgds,
Pradeep

Edited by: KINO on Sep 14, 2008 4:53 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 12 2008
Added on Sep 14 2008
37 comments
3,700 views