|
Operating systems: i5/OS, Linux,Windows |
The information in this topic applies only to the IBM Portlet API.
Portlet menus allow a portlet to add menu entries to the navigation tree of the portal. Menu items are automatically positioned in the navigation tree after the page that contains the portlet instance. The root node of this tree represents the portlet and all child nodes represent portlet menu entries. Portlet menu entries do not belong to the internal portal model. For example, they cannot be modified or removed using the page customizer.
The portlet menu nodes contain a URL that either points to the portlet itself or to an external page. When the menu nodes refer to the portlet, the URL includes an action string on which the portlet code can react, and one or more request parameters, which the portlet can use. It is not possible that the menu nodes point to another portlet or page of the portal than the portlet which created them.
To add menu entries to the portal navigation tree, portlets must implement the MenuProvider interface. The portlet implementing MenuProvider must provide a getMenu() method, which returns a tree model instance of the MenuTree class to display in the portal navigation. To create a new instance of a MenuTree, the getMenuTree() method of one of the provided service classes can be used. They are located in the package com.ibm.wps.portletservice.portletmenu.
To simplify the development of portlet menus, your portlet should extend one of the provided helper classes that implement the MenuProvider interface. These helper classes create the instance of MenuTree using the PortletService classes. The portlet menu helper classes are located in the com.ibm.wps.portlets.menu package in wpsportlets.jar. The Javadoc for the helper classes can be found in the portal_server_root/dev/samples directory.
The choice of which helper class to use depends on how the portlet should implement the menu:
The following steps show how to use Rational Application Developer to create a portlet that adds a simple static menu to the portal navigation. To get started, open Rational Application Developer in the Web perspective.
<config-param>
<param-name>XMIFilePath</param-name>
<param-value>menu-tree.xml</param-value>
</config-param>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE menu-tree PUBLIC "-//IBM//DTD Portlet Menu 1.0//EN" "menu-tree.dtd" >
<menu-tree>
<menu-node id="rootId">
<display-info>
<locale>en</locale>
<title>XMI Test Portlet</title>
<description>XMI Tree Description</description>
</display-info>
<display-info>
<locale>fr</locale>
<title>XMI Test Portlet</title>
<description>XMI Tree Description</description>
</display-info>
<!-- node 1 -->
<menu-node id="id1">
<display-info>
<locale>en</locale>
<title>Node 1</title>
<description>Node 1 Description</description>
</display-info>
<display-info>
<locale>fr</locale>
<title>Noeud 1</title>
<description>Noeud 1 Description</description>
</display-info>
<action-name>Node1Action</action-name>
<param id="n1-pid1">
<param-name>Param1Name</param-name>
<param-value>Node1Param1Value</param-value>
</param>
<param id="n1-pid2">
<param-name>Param2Name</param-name>
<param-value>Node1Param2Value</param-value>
</param>
<!-- node 1.1 -->
<menu-node id="id1_1">
<display-info>
<locale>en</locale>
<title>Node 1.1</title>
<description>Node 1.1 Description</description>
</display-info>
</menu-node>
<!-- node 1.2 -->
<menu-node id="id1_2">
<display-info>
<locale>en</locale>
<title>Node 1.2</title>
<description>Node 1.2 Description</description>
</display-info>
</menu-node>
</menu-node>
<!-- node 2 -->
<menu-node id="id2">
<display-info>
<locale>en</locale>
<title>Node 2</title>
<description>Node 2 Description</description>
</display-info>
<display-info>
<locale>fr</locale>
<title>Noeud 2</title>
<description>Noeud 2 Description</description>
</display-info>
<action-name>Node2Action</action-name>
<param id="n2-pid1">
<param-name>Param1Name</param-name>
<param-value>Node2Param1Value</param-value>
</param>
<param id="n2-pid2">
<param-name>Param2Name</param-name>
<param-value>Node2Param2Value</param-value>
</param>
</menu-node>
</menu-node>
</menu-tree>
import com.ibm.wps.portlet.menu.*; import com.ibm.wps.portlets.menu.*; import org.apache.jetspeed.portlet.event.*;
public class MyPortlet extends XMIMenuTreePortlet
implements MenuProvider, ActionListener
public void actionPerformed(ActionEvent event) throws PortletException
{
if (event.getAction()!=null){
String actionString = event.getActionString();
PortletRequest request = event.getRequest();
if (actionString != null)
{
request.setAttribute("ActionString", actionString);
}
}
}
public class MyPortlet extends XMIMenuTreePortlet {
You can debug the portlet locally or export the portlet to a WAR file and test it on a remote server.