[thelist] Java/JSP puzzler revisited (simplified) - almost there!

Hassan Schroeder hassan at webtuitive.com
Thu Oct 20 15:22:37 CDT 2005


Tom Dell'Aringa wrote:

> The only issue is I seem to be getting a double ending LI like so:
> 
> </li></li>
> 
> After each list item. And when a UL starts, it must start in an OPEN LI like so:
> 
> <li>blah blah
>    <ul>
>      <li>blah</li>
>    </ul>
> </li>

This is hard without a runnable example, but try these changes :-)

> <%
> 	ListIterator verticalNodes = nodesInVerticalOrder.listIterator();
> 	if (!verticalNodes.hasNext()) return;
> 	int level = 1;
> 	int previousLevel = 1;
> 
> 	StringBuffer dataCell = new StringBuffer();
> 	StringBuffer javaScript = new StringBuffer();
> 	
> 	// start UL
> 	dataCell.append("<ul>");
> 
> 	// iterate through each nav item and write it out
> 	while (verticalNodes.hasNext()) {
> 
> 		MenuItemNode node = (MenuItemNode) verticalNodes.next();
> 
> 		previousLevel = level;
> 		level = node.getLevel();  // # from 1-4
> 		
> 		//if ( verticalNodes.hasPrevious() )
	if ( verticalNodes.hasPrevious() && level == previousLevel )
> 		{
> 			dataCell.append("</li>");
> 		}
> 		if ( level > previousLevel )
> 		{
> 			dataCell.append("<ul>");
> 		}
> 		if ( level < previousLevel )
> 		{
> 		//	dataCell.append("</ul>");
		/* add the post-ul-close /li here */
			dataCell.append("</ul></li>");
> 		}
> 	
> 		// begin new list item, write out class name and link
> 		dataCell.append("<li><a href=\"" + node.getHref() + "\"");
> 		//close the href, write the anchor text, close the anchor.
> 		dataCell.append(">" + node.getTitle() + "</a>");
> 		// end of list item and link
> 
> 		//close the LI item

	/* I believe this next line is unnecessary -- since it's
	 * closed by the verticalNodes.hasPrevious() above...
	 * -- thought I deleted it in the sample sent off-list
	 */
> 	     //	dataCell.append("</li>\n");
> 	}
> 	// close out the UL
	dataCell.append("</li>"); /* to close the final list item */
> 	dataCell.append("</ul>");
> %>

Try that and send me the output :-)

-- 
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com

                          dream.  code.





More information about the thelist mailing list