Websphere Portal theme navigation context menus

May 1st, 2009 by Brian | Filed under work.

I spend a lot of my day working with WebSphere Portal server, and as of late, spending more time (than I’d like!) with themes & skins. I am currently working with Portal v6.1, but the information below should be useful for previous versions as well.WebSphere software

Our portal is pretty open, we want people to come in & customize it as much as they’d like. One feature that we allow is for the user to come in & create new pages. We are running our own theme policy which is a copy of the DoubleTopNav policy. Our theme displays these 2 levels of navigation at the top, and we have no side navigation.

The hurdle I ran into was – how do I prevent the “New Page” option from appearing in the portlet menu for pages in the second level of navigation? The way the out-of-the-box Portal theme works is that when you create a new page, it is created as a child of the page that you are on. This works fine for top level pages, but there no policy or rule that can be set to prevent the “New Page” option from appearing in the portlet menu for second level pages.

The solution, proposed by a member of the Portal team was to create an alternate pageContextMenu.jsp which simply didn’t have a “New Page” option. Since the call the that JSP is done via AJAX, prior to the call we can determine what navigation level we are on and call the appropriate version of pageContextMenu.jsp.

Piece of cake, right? Eh .. maybe not cake, but not all that difficult. After creating the new pageContextMenu2.jsp & removing the “New Page” option, the next place to go is head_inlineJS.jspf. Below is the code I have added/modified to the head_inlineJS.jspf.

  1. <%– START – see if we are in 2nd level of navigation –%>
  2. <%
  3. String pageContextMenuJSP = "pageContextMenu";
  4. %>
  5. <portal-navigation:navigation startLevel="2" stopLevel="3">
  6.   <portal-navigation:navigationLoop>
  7.     <portal-logic:if nodeInSelectionPath="yes">
  8.     <%
  9.       //it’s in selection path &amp; it’s selected (this is the page we are on!
  10.       if (wpsSelectionModel.isNodeSelected(wpsNavNode)){
  11.         int level = wpsNavLevel.intValue();
  12.         if (level == 2) {
  13.           pageContextMenuJSP = "pageContextMenu2";
  14.         }
  15.       }
  16.     %>
  17.     </portal-logic:if>
  18.   </portal-navigation:navigationLoop>
  19. </portal-navigation:navigation>
  20. <%– END – see if we are in 2nd level of navigation –%>
  21.  
  22. <%– Context Menu Initialization –%>
  23. <c-rt:set var="pageNoActionsText" ><portal-fmt:text bundle=‘nls.engine’ key=‘info.emptymenu’ /></c-rt:set>
  24. (function(){
  25.  
  26. var pageMenuURL = ‘<portal-navigation:url themeTemplate="<%=pageContextMenuJSP%>" />’;
  27. <%– OLD var pageMenuURL = ‘<portal-navigation:url themeTemplate="pageContextMenu" />’; –%>

Now that you’ve got that taken care of, touch head.jspf && touch Default.jsp, reload your page and you should no longer see “New Page” as an option in the page drop down for pages in the 2nd level of your navigation.

That worked and was a thing of beauty .. well, almost. I wasn’t a big fan of looping through the entire navigation model, but I didn’t know any other way. I ran the code past my colleague from the Portal team and he pointed me at the navigationSelectionModel. The code below is smaller & faster. Best of all – it works :)

  1. <%– 2009.05.04 OLORE – see if we are in 2nd level of navigation –%>
  2. <%
  3. String pageContextMenuJSP = "pageContextMenu";
  4.  
  5. int level_count = 0;
  6. for (java.util.Iterator i = nsm.iterator(); i.hasNext(); ) {
  7.   NavigationNode node = (NavigationNode) i.next();
  8.     level_count++;
  9. }
  10. if (level_count >= 4) { // level 4 == our 2nd level of top navigation (shouldn’t ever be >)
  11.   pageContextMenuJSP = "pageContextMenu2";
  12. }
  13.  
  14. %>
  15. <%– 2009.05.04 OLORE – see if we are in 2nd level of navigation –%>
  16.  
  17. <%– Context Menu Initialization –%>
  18. <c-rt:set var="pageNoActionsText" ><portal-fmt:text bundle=‘nls.engine’ key=‘info.emptymenu’ /></c-rt:set>
  19. (function(){
  20.  
  21.   <%– 2009.05.01 OLORE – use pageContextMenu2 if we are in 2nd level nav –%>
  22.   var pageMenuURL = ‘<portal-navigation:url themeTemplate="<%=pageContextMenuJSP%>" />’;
  23.   <%– 2009.05.01 OLORE – use pageContextMenu2 if we are in 2nd level nav –%>

Tags: , , ,

2 Responses to “Websphere Portal theme navigation context menus”

  1. ivan | 20/07/09

    Hi Brian,
    Id like to ask you for your advise. Im am a websphere admin and my boss purchased website template with all css, html and flash stuff. He wants me to import the design into websphere portal for our customers to see. How do i do that..? Since im not a programmer and coding is not my particular brand of Vodka, im not sure how to import all the grafical elements into existing portal 6.0. Your advice and comments will be appreciated.

    Thank you

  2. Brian | 21/07/09

    Hi ivan, I don’t envy your position. It’s not going to be easy. Your best bet is to follow the instructions in the InfoCenter about Creating your own theme. Once you do that & deploy it, start picking through the JSPs and making small changes & testing them. The main files you’ll want to look at are head.jspf, Default.jsp, styles.jsp and js.jsp

    Good luck!
    -brian

Share Your Thoughts