com.ibm.wps.portlets.menu
Class MemoryMenuTreePortlet
java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
com.ibm.wps.pe.pc.legacy.cache.CacheablePortlet
org.apache.jetspeed.portlet.Portlet
org.apache.jetspeed.portlet.PortletAdapter
com.ibm.wps.portlets.menu.MemoryMenuTreePortlet
- All Implemented Interfaces:
- com.ibm.websphere.servlet.cache.CacheableServlet, MenuProvider, java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig, org.apache.jetspeed.portlet.PortletSessionListener
Deprecated. since 6.0. Support of the IBM portlet API may be removed in a future
release of WebSphere Portal. Use of the Java Portlet API (javax.portlet)
is recommended instead.
-
public abstract class MemoryMenuTreePortlet
- extends org.apache.jetspeed.portlet.PortletAdapter
- implements MenuProvider
MemoryMenuTreePortlet is a convenience implementation of a portlet that exposes a dynamic
(memory based) portlet menu. Custom subclasses of MemoryMenuTreePortlet need to
make sure that the menu is filled with appropriate dynamic information.
The MemoryMenuTreePortlet is a default implementation for the
Portlet interface. If a portlet uses an an in-memory menu tree,
it is recommended that it derives from MemoryMenuTreePortlet.
The controller interface MenuTreeTopologyCtrl enables adding or
removing tree nodes. The controller interface MenuTreeInfoCtrl
can be used to set title and description of the node and to add an URI action and one or
more parameters to the node.
The following example shows how MenuProvider#getMenuTree can be extended
to create a menu tree with two nodes and two subnodes of the first node. Title and description
are set in two different locales. To avoid that the memory tree is created at each request,
it is recommended to store the tree instance, e.g., as a session attribute.
Portlet source code:
import org.apache.jetspeed.portlet.*;
import org.apache.jetspeed.portlet.event.*;
import com.ibm.wps.portlet.menu.*;
import com.ibm.wps.portlets.menu.*;
import java.util.*;
import java.io.*;
public class MemoryTestPortlet extends MemoryMenuTreePortlet
implements MenuProvider, ActionListener
{ public void doView(PortletRequest request, PortletResponse response)
throws PortletException, IOException
{ // Invoke the JSP to render
getPortletConfig().getContext().include("/jsp/View.jsp", request, response);
}
// action event handling
public void actionPerformed(ActionEvent event) throws PortletException
{ if (event != null)
{ String actionString = event.getActionString();
PortletRequest request = event.getRequest();
if (actionString != null)
{ request.setAttribute("ActionString", actionString);
}
}
}
// overwrites implementation of MemoryMenuTreePortlet
public MenuTree getMenuTree(MenuContext menuContext) throws PortletException
{ // session stores menu tree
PortletSession session = menuContext.getPortletRequest().getPortletSession();
MenuTree menuTree = (MenuTree) session.getAttribute("menu-tree");
if ( menuTree == null )
{ // use method implementation of MemoryMenuTreePortlet
menuTree = super.createEmptyMenuTree(menuContext);
// get the controllers
MenuTreeInfoCtrl ctrlInfo = (MenuTreeInfoCtrl) menuTree;
MenuTreeTopologyCtrl ctrlTopology = (MenuTreeTopologyCtrl) menuTree;
try
{ // get the root
MenuNode rootNode = menuTree.getRoot();
// set scope
ctrlTopology.setScope(rootNode,MenuNode.SCOPE_REQUEST);
// add root node title and description
ctrlInfo.setInformation(Locale.ENGLISH,"Memory Tree","Memory Tree",rootNode);
ctrlInfo.setInformation(Locale.FRENCH,"Memory Tree","Memory Tree",rootNode);
// add two new nodes with title and description
MenuNode node1 = ctrlTopology.addNode("id1",rootNode);
ctrlInfo.setInformation(Locale.ENGLISH,"Node 1","Node 1",node1);
ctrlInfo.setInformation(Locale.FRENCH,"Noeud 1","Noeud 1",node1);
MenuNode node2 = ctrlTopology.addNode("id2",rootNode);
ctrlInfo.setInformation(Locale.ENGLISH,"Node 2","Node 2",node2);
ctrlInfo.setInformation(Locale.FRENCH,"Noeud 2","Noeud 2",node2);
MenuNode node3 = ctrlTopology.addNode("id3",rootNode);
ctrlInfo.setInformation(Locale.ENGLISH,"Node 3","Node 3",node3);
ctrlInfo.setInformation(Locale.FRENCH,"Noeud 3","Noeud 3",node3);
// add two subnodes to node1 with title and description
MenuNode node1_1 = ctrlTopology.addNode("id1_1",node1);
ctrlInfo.setInformation(Locale.ENGLISH,"Node 1.1","Node 1.1",node1_1);
ctrlInfo.setInformation(Locale.FRENCH,"Noeud 1.1","Noeud 1.1",node1_1);
MenuNode node1_2 = ctrlTopology.addNode("id1_2",node1);
ctrlInfo.setInformation(Locale.ENGLISH,"Node 1.2","Node 1.2",node1_2);
ctrlInfo.setInformation(Locale.FRENCH,"Noeud 1.2","Noeud 1.2",node1_2);
// set action and add parameter-value pairs to node1
ctrlInfo.setAction("Node1Action",node1);
ctrlInfo.addActionParameter("Param1Name","Node1Param1Value",node1);
ctrlInfo.addActionParameter("Param2Name","Node1Param2Value",node1);
// set action and add parameter-value pairs to node2
ctrlInfo.setAction("Node2Action",node2);
ctrlInfo.addActionParameter("Param1Name","Node2Param1Value",node2);
ctrlInfo.addActionParameter("Param2Name","Node2Param2Value",node2);
// set url to node3
ctrlInfo.setURL("http://www.ibm.com/us/",node3);
}
catch ( MenuTreeException ex )
{ throw new PortletException("Exception creating tree", ex);
}
session.setAttribute("menu-tree", menuTree);
}
return menuTree;
}
}
with /jsp/View.jsp
<%@ page contentType="text/html"%>
<H3>Test of MemoryMenuTree</H3>
<UL>
<LI>Expand root node and <CITE>Node 1</CITE>.<BR><BR>
</LI>
<LI>Click <CITE>Node 1</CITE> and <CITE>Node 2</CITE>. Check if action string and request parameters are displayed.
<TABLE BORDER="0">
<TR>
<TD>Action:</TD>
<TD><%=request.getAttribute("ActionString")%></TD>
</TR><TR>
<TD>Param1:</TD>
<TD><%=request.getParameter("Param1Name")%></TD>
</TR><TR>
<TD>Param2:</TD>
<TD><%=request.getParameter("Param2Name")%></TD>
</TR>
</TABLE>
<BR>
</LI>
<LI>Click <CITE>Node 3</CITE>. Check if external html page is displayed and return to portal page.
</LI>
</UL>
- Since:
- 5.0
- See Also:
- PortletAdapter,
MenuProvider,
MenuTreeTopologyCtrl,
MenuTreeInfoCtrl,
Serialized Form
Nested classes/interfaces inherited from class org.apache.jetspeed.portlet.Portlet
|
org.apache.jetspeed.portlet.Portlet.Mode, org.apache.jetspeed.portlet.Portlet.ModeModifier |
Method Summary
|
protected MenuTree |
createEmptyMenuTree(MenuContext menuContext)
Deprecated. Return a memory menu tree with only one unnamed root node,
do not overwrite, but call this method from the derived class. |
MenuTree |
getMenu(MenuContext menuContext)
Deprecated. Return a memory menu tree with only one unnamed root node for a specified context,
overwrite with the custom portlet implementation. |
protected MenuTree |
getMenuTree(MenuContext menuContext)
Deprecated. Return a memory menu tree with only one unnamed root node for a specified context,
overwrite with the custom portlet implementation. |
Methods inherited from class org.apache.jetspeed.portlet.PortletAdapter
|
destroy, destroyConcrete, doConfigure, doEdit, doHelp, doView, getLastModified, getPortletConfig, getPortletLog, getVariable, init, initConcrete, login, logout, removeVariable, service, setVariable |
Methods inherited from class org.apache.jetspeed.portlet.Portlet
|
destroy, doGet, doPost, doPut, getId, getInitParameter, getInitParameterNames, getLastModified, getPortletSettings, getServletContext, getServletInfo, init, service |
Methods inherited from class javax.servlet.http.HttpServlet
|
doDelete, doHead, doOptions, doTrace |
Methods inherited from class javax.servlet.GenericServlet
|
getServletConfig, getServletName, init, log, log |
Methods inherited from class java.lang.Object
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MemoryMenuTreePortlet
protected MemoryMenuTreePortlet()
- Deprecated.
- Constructor.
getMenu
public MenuTree getMenu(MenuContext menuContext)
throws org.apache.jetspeed.portlet.PortletException
- Deprecated.
- Returns a memory menu tree with only one unnamed root node for a specified context,
overwrite with the custom portlet implementation.
As of release 5.0, this method can be implemented as well as getMenuTree().
- Specified by:
- getMenu in interface MenuProvider
- Parameters:
- menuContext - menu context contains the current request ID and response ID.
- Returns:
- the memory menu tree with only the root node which has the node ID RootId.
To get this ID, apply menuTree.getRoot().getId() to the returned menuTree.
- Throws:
- org.apache.jetspeed.portlet.PortletException - if service not found or unavailable
- See Also:
- MenuProvider
getMenuTree
protected MenuTree getMenuTree(MenuContext menuContext)
throws org.apache.jetspeed.portlet.PortletException
- Deprecated.
- Returns a memory menu tree with only one unnamed root node for a specified context,
overwrite with the custom portlet implementation.
As of release 5.0, this method can be implemented as well as getMenu().
- Parameters:
- menuContext - contains the current request ID and response ID.
- Returns:
- the memory menu tree with only the root node which has the node ID RootId.
To get this ID, apply menuTree.getRoot().getId() to the returned menuTree.
- Throws:
- org.apache.jetspeed.portlet.PortletException - if service not found or unavailable
createEmptyMenuTree
protected MenuTree createEmptyMenuTree(MenuContext menuContext)
throws org.apache.jetspeed.portlet.PortletException
- Deprecated.
- Returns a memory menu tree with only one unnamed root node,
do not overwrite, but call this method from the derived class.
- Parameters:
- menuContext - contains the current request ID and response ID.
- Returns:
- the memory menu tree with only the root node which has the node ID RootId.
To get this ID, apply menuTree.getRoot().getId() to the returned menuTree.
- Throws:
- org.apache.jetspeed.portlet.PortletException - if service not found or unavailable