[opencms-dev] building a simple tree nav-left
Joe Desbonnet
jdesbonnet at gmail.com
Mon Oct 10 14:09:50 CEST 2005
Something like this should do what you want. You can delare the
following function in your JSP between <%! and %> marks. Or you can
just include the body of this function in your JSP code. You will need
to create the 'cms' object: an instance of the CmsJspActionElement
object. (eg like this: CmsJspActionElement cms = new
CmsJspActionElement(pageContext, request, response);
/**
* Write left side navigation as simple nested bulleted lists. Use stylesheet
* to alter presentation.
*/
private void writeLeftNavigation (CmsJspActionElement cms, Writer out)
throws IOException {
out.write ("<ul class=\"level0\">\n");
out.write ("<li><a href=\"" + cms.link("/") + "\">Home</a></li>\n");
Iterator iter =
cms.getNavigation().getSiteNavigation(cms.getCmsObject(),"/",3).iterator();
int currentLevel = 0;
String uri = cms.getCmsObject().getRequestContext().getUri();
if (uri.endsWith("/index.html")) {
uri = uri.substring(0,uri.length() - 10);
}
int level;
String resourceName;
while (iter.hasNext()) {
CmsJspNavElement nav = (CmsJspNavElement)iter.next();
level = nav.getNavTreeLevel();
resourceName = nav.getResourceName();
if (level > currentLevel) {
out.write ("<ul class=\"level" + level + "\">\n");
currentLevel = level;
}
if (level < currentLevel) {
out.write ("</ul>\n");
currentLevel = level;
}
if (uri.equals(resourceName)) {
out.write ("<li class=\"active\">");
} else {
out.write ("<li>");
}
out.write ("<a href=\"" + cms.link(resourceName) + "\">" +
nav.getNavText() + "</a></li>\n");
}
for (int i = 0; i < currentLevel; i++) {
out.write ("</ul>");
}
out.write ("<li><a href=\"" + cms.link ("/sitemap.jsp") +
"\">Sitemap</a></li>\n");
out.write ("</ul>\n");
}
On 10/10/05, Francisco Lopera <flopera at encamina.com> wrote:
>
>
> Hello.
>
> I need build a tree navigator like "navleft" of template one. Opening the
> element navleft.jsp I see this code:
>
> <%@page buffer="none" session="false" import="org.opencms.file.*,
> org.opencms.jsp.*, java.util.*,
> org.opencms.frontend.templateone.*" %><%
>
> // initialize action element to access the API
> CmsTemplateNavigation cms = new
> CmsTemplateNavigation(pageContext, request, response);
>
> %><%= cms.buildNavigationLeft() %><% cms.buildNavLeftIncludeElement(); %>
>
>
> I can't find any reference to buildNavigationLeft in javadoc or templateOne
> files.
>
> Somebody have a good navleft builded?
>
> Thanks.
>
>
> _______________________________________________
> This mail is send to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://mail.opencms.org/mailman/listinfo/opencms-dev
>
>
>
More information about the opencms-dev
mailing list