[thelist] Java Logic question for you experts

Tom Dell'Aringa pixelmech at yahoo.com
Wed Oct 19 16:23:25 CDT 2005

I've got a logic issue I can't get my head around. The situation is that I have inherited an old
installation of an Epicentric Portal (internal) that was customized years ago. The nav currently
uses images written out by a jsp. It's horribly slow, so I'm attempting to rewrite the code to use
text only, with styled ULs instead. 

I got to the point where I removed the images and was able to use the code to write out a nice UL
with every nav item (vertically) as a LI, with an anchor inside. It works where if you click on a
nav item that has children, they show up fine, but the style is off. My first solution was to
write a class to the various levels of navigation (n1-n4, below) and indent the LIs. It will work,
but it's kludgy, and the presentation will not be how I want it.

What I really want is to have each level of navigation, as you drill down, be its OWN UL. Like so:

<li>level one
     <li>level two
            <li>level three</li>
            <li>level three</li>
     <li>level two</li>
     <li>level two</li>
<li>level one</li>
<li>level one</li>

That will allow me to do all the nifty CSS things I want to do. Problem is, I can't figure out how
to do that. Below is the code that I have which I think is 90% there. At the point where the line:

if (node.isSelected() | node.wasSelected()) {

is where I'm currently writing out an 'active' class, and I think that is where the nested UL
should begin. I cannot seem to figure out how to write all the nested LIs within the correct UL.
The stuff I tried (commented out) only got me ONE LI in a nested UL, not right. 

The code below is all I have access to - there is nothing else. Hopefully someone can shed some
light on this problem. My best guess is there needs to be another while loop possibly comparing
indentWidth values...but I can't get anything to work.

Any help is greatly appreciated!

Code below:
	Iterator verticalNodes = nodesInVerticalOrder.iterator();
	if (!verticalNodes.hasNext()) return;

	StringBuffer dataCell = new StringBuffer();
	StringBuffer javaScript = new StringBuffer(); 
	int jscriptindex = 1;
	int navindex = 1;	// current iteration through the nav generation loop
	int selectedindex = 0;	// menu item that should be set as selected
	// start UL

	// iterate through each nav item and write it out
	while (verticalNodes.hasNext()) {

		MenuItemNode node = (MenuItemNode) verticalNodes.next();

		int level = node.getLevel();
		// indentWidth will be 7,14,21 or 28 - indicating what level the nav is at
		String indentWidth = String.valueOf((1+level-startLevel) * 7); 
		int i = Integer.parseInt(indentWidth);
		String className = "";
		// set a classname to indent the LIs
		switch (i) {
		  case 7 :
		    className = "n1";
		  case 14 :
		    className = "n2";
		  case 21 :
		    className = "n3";
		  case 28 :
		    className = "n4";
		  default :
		    className = "";
		// begin new list item, write out class name
		dataCell.append("<li class=\"" +className+ "\">");
		// possibly write out sub ULs - but seems to only write out one at a time, not the
		// full block we need...
		/*if (node.isSelected() | node.wasSelected()) {
		dataCell.append("<a href=\"");
		dataCell.append(node.getHref() + "\"");
		// write a class on the active path links to highlight them
		if (node.isSelected() | node.wasSelected()) {
			dataCell.append(" class='active'");
		//close the href, write the anchor text, close the anchor.
		dataCell.append(">" + node.getTitle() + ""); 
		// end sub UL..not working yet..
		/*if (node.isSelected()  | node.wasSelected()) {
		//close the LI item
	// close out the UL

<!-- begin output of nav -->
<div id="svmp_vert">
<%= dataCell.toString() %>
<!-- end Nav-Vert Area -->




A man spoke frantically into the phone: "My wife is pregnant and her contractions are only two minutes apart"! "Is this her first child?" the doctor asked. "No, you idiot!" the man shouted. "This is her husband!"

Q: What do you call a muddy chicken who crossed the road two times?
A: A dirty double crosser...

More information about the thelist mailing list