troubleshooting Question

how to write it recursively

Avatar of chaitu chaitu
chaitu chaituFlag for India asked on
JavaJSPJava EE
4 Comments1 Solution416 ViewsLast Modified:
how to construct the below HTML ;as you can see the table data can be multiply nested.

 while(rs.next())
		 {
			 
			 al.add(rs.getInt("ID"));
			 
			 Menu m = new Menu();
			 m.setId(rs.getInt("ID"));
			 m.setName(rs.getString("NAME"));
			 m.setMenuId(rs.getInt("PARENT_ID"));
			 
			 if(al.contains(rs.getInt("PARENT_ID")))
			 {
				 System.out.println("in if...................");
				 
				 ArrayList<SubMenu> subMenuList = new  ArrayList<SubMenu>();
				 SubMenu sm = new SubMenu();
				 sm.setId(rs.getInt("ID"));
				 sm.setName(rs.getString("NAME"));
				 sm.setMenuId(rs.getInt("PARENT_ID"));
				 subMenuList.add(sm);
				 m.setSubMenuList(subMenuList);
			 }
			 
			 System.out.println(m);
			 
		 }

    <li>
		   <a href="#" class="parent"><span>Menu 1</span></a>
				<div>
					<ul>
						<li><a href="#" ><span>Page 1</span></a></li>
						<li><a href="#" ><span>Page 2</span></a>
						
						<div>
				<ul>
					<li><a href="#" ><span>Page 4</span></a></li>
					<li><a href="#" ><span>Page 5</span></a></li>
				</ul>
					</div>
						</li>
					</ul>
				</div>
		</li>



		<li>
			<a href="#" class="parent"><span>Menu 2</span></a>
			<div>
				<ul>
					<li><a href="#" ><span>Page 3</span></a></li>
				</ul>
			</div>
		</li>


		 <li>
			 <a href="#" class="parent"><span>Help</span></a>
			 <div>
				<ul>
					<li><a href="#" ><span>About</span></a></li>
				</ul>
			</div>
		 </li>
 

this is the data from the table.
ID            NAME      PARENT_ID LINKS    ACTION
4	page1	1	/images/email.gif	page1
2	Menu2	(null)	(null)	                Menu2
1	Menu1	(null)	/images/home.gif	Menu1
3	Help	(null)	(null)	                Help
5	page2	1	(null)	                page2
6	page3	2	/images/photo.gif	page3
7	about	3	(null)	               about
8	page4	5	/images/photo.gif	page3
9	page5	5	(null)	               about
ASKER CERTIFIED SOLUTION
zzynx
Sr. Software engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros