In a portal application all the navigation is theoretically pre-defined, since the structure of the portal application is defined in a hierarchal way. For example, to the right is the structure of the portal file created using Weblogic Portal 8.1.
To create the breadcrumbs for this portal application we simply have to iterate through the structure of the portal file, starting with the current page and working upwards towards the root.
The code to accomplish this is below (slight tweaks may be required for your own use). This code is specific to Weblogic Portal 8.1 but the basic concept should be applicable to all portal platforms. In this particular example all the code is saved in a single JSP file. (Sorry, I know the code is ugly):
<%@ page import="com.bea.netuix.servlets.controls.page.PagePresentationContext, com.bea.netuix.servlets.controls.page.BookPresentationContext, com.bea.netuix.servlets.controls.application.DesktopPresentationContext com.bea.netuix.servlets.controls.PresentationContext, com.bea.portlet.PageURL, java.util.List" %> <% ArrayList breadcrumbs = new ArrayList(); PagePresentationContext pageCtx = PagePresentationContext.getPagePresentationContext(request); do { PagePresentationContext parentPageCtx = pageCtx.getParentPagePresentationContext(); String title; String url; if (pageCtx instanceof BookPresentationContext) { title = pageCtx.getTitle(); url = PageURL.createPageURL(request, response, ((BookPresentationContext)pageCtx).getDefaultPage()).toString(); } else { title = pageCtx.getTitle(); url = PageURL.createPageURL(request, response, pageCtx.getDefinitionLabel()).toString(); } if (parentPageCtx == null) { title = "Home"; } if (!( parentPageCtx != null && parentPageCtx instanceof BookPresentationContext && ((BookPresentationContext)parentPageCtx).getDefaultPage().equals(pageCtx.getDefinitionLabel()) )) { breadcrumbs.add(new String[] {title, url}); } pageCtx = parentPageCtx; } while (pageCtx != null); %> <p class="x-small bold"> <% for (int i = breadcrumbs.size() - 1; i >= 0; i--) { String title = ((String[])breadcrumbs.get(i))[0]; String url = ((String[])breadcrumbs.get(i))[1]; if (i > 0) { %> <a class="breadcrumb-hyperlink" href="<%=url%>"><%=title%></a> > <% } else { %> <%=title%> <% } } %> </p>
No comments:
Post a Comment