Dashboard > Community Wiki Archive > Home > Top Menu Example
Top Menu Example Log In View a printable version of the current page.

Added by GrĂ©gory Joseph , last edited by GrĂ©gory Joseph on May 09, 2008  (view change)
Labels: 

If you want to have a top navigation like I did on my Website, here is the jsp code.

<%@ page import="com.obinary.cms.core.Content, 
com.obinary.cms.core.HierarchyManager, 
java.util.Iterator, 
java.util.Collections, 
java.util.ArrayList, 
com.obinary.cms.util.Resource, 
java.util.Collection"%> 
<%@ taglib uri="cms-taglib" prefix="cms" %> 
<%@ taglib uri="cms-util-taglib" prefix="cmsu" %> 
<%@ taglib uri="JSTL" prefix="c" %> 

<%! 
private int drawChildren(JspWriter out,Content page,String activePageHandle,int indent) { 
String activePage = activePageHandle + "/"; 
int level = 0; 
Iterator it=page.getChildren().iterator(); 
int count = 0; 
Content nextContent = null; 
try { 
while (it.hasNext()) { 
count++; 
if (count == 1) 
{ 
level++; 
out.println("<tr><td colspan=2 class=line></td></tr>\n"); 
out.println("<tr><td><img class='navLine' 
src='/docroot/rhg/imgs/0.gif'></td><td><table><tr>\n"); 
} 
Content c=(Content) it.next(); 
String cssClassA="nav"; 
String cssClassTd="nav"; 
String handle = c.getHandle(); 
if (activePage.indexOf(handle + "/")==0) cssClassA="navHi"; 
out.print("<td class="+cssClassTd+" style=padding-left:"+indent+";>"); 
out.print("<a href="+c.getHandle()+".html class="+cssClassA+">"+c.getTitle()+"</a><br>"); 
out.print("</td>"); 
if (activePage.indexOf(handle + "/")==0) { 
nextContent = c; 
} 
} 
if (count > 0) 
{ 
out.println("</tr></table></td></tr>\n"); 
} 
} 
catch (Exception e) {} 
if (nextContent != null) 
{ 
level += drawChildren(out,nextContent,activePageHandle,indent); 
} 
return level; 
} 

%> 
<% 
int navlevel = 1; 
%> 

<%-- loop the ancestors (path to the page) --%> 
<% 
//ancestors (no reverse access in jsp yet) 
Collection pageAncestors = Resource.getActivePage(request).getAncestors(); 
ArrayList pageAnc = new ArrayList(pageAncestors); 
Collections.reverse(pageAnc); 
Iterator pageIt = pageAnc.iterator(); 
String startPage = Resource.getActivePage(request).getHandle(); 
while (pageIt.hasNext()) { 
Content c = (Content) pageIt.next(); 
if (c.getLevel() == navlevel){ 
startPage = c.getHandle(); 
} 
} 
String navStart = startPage; 
%> 

<c:if test="${isPortalDoc==true}"> 
<% 
navStart = (String) pageContext.getAttribute("baseHandle"); 
%> 
</c:if> 

<table class="navigation" cellpadding="0" cellspacing="0" width="100%"> 
<% 
HierarchyManager hm=Resource.getHierarchyManager(request); 
//Content root=hm.getPage("/"); 
Content root=hm.getPage(navStart); 
String activePageHandle=Resource.getActivePage(request).getHandle(); 
int levels = drawChildren(out,root,activePageHandle,10); 
%> 
<tr><td colspan=2 class=line></td></tr> 
<% 
while (levels < 3) 
{ 
levels++; 
%> 
<tr><td colspan=2><img class="navLine" src="/docroot/imgs/0.gif"></td></tr> 
<tr><td colspan=2 class=line></td></tr> 
<% 
} 
%> 
</table>
Powered by a free Atlassian Confluence Open Source Project License granted to Magnolia International. Evaluate Confluence today.
Powered by Atlassian Confluence 2.7, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators