spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / java / jspmenus To page 1To page 2To page 3current page
[previous]

A Java-JSP Menu Builder for HierMenus

Systems Engineer Sr – Automation – Opsware SAS / HP SA
Next Step Systems
US-PA-Philadelphia

Justtechjobs.com Post A Job | Post A Resume
Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans


Replace the Hierarchical Menu HM_Arrays.js

The HierMenus JavaScript file HM_Loader.js has default parameters that set up the look and feel of the menu. This file internally loads HM_Arrays.js and the Netscape and IE specific JavaScript files needed to drive the menu. To replace the HM_Arrays.js, you have to follow these steps:

  • Copy and paste the JSP code below into a new file and save it as menu.jsp.

  • Save HM_Loader.js, HM_ScriptNS4.js, HM_ScriptIE4.js and HM_ScriptDOM.js (all from the HierMenus distribution) in the directory structure under the \js folder.

  • Comment the following line in HM_Loader.js (line wrapped here for better formatting on this page):

    document.write("<SCR" + "IPT LANGUAGE='JavaScript1.2' 
                    SRC='HM_Arrays.js' 
                    TYPE='text/javascript'><\/SCR" + "IPT>");

    This line is removed as we won’t be using HM_Arrays.js anymore.

Your final directory structure should look like this

{webapp_directory}\menu-app\menu.jsp
{webapp_directory}\menu-app\js\HM_Loader.js
{webapp_directory}\menu-app\js\ HM_ScriptNS4.js
{webapp_directory}\menu-app\js\ HM_ScriptIE4.js 
{webapp_directory}\menu-app\js\ HM_ScriptDOM.js
{webapp_directory}\menu-app\WEB-INF\classes\HMContentTree.class
{webapp_directory}\menu-app\WEB-INF\classes\ HMContentTreeRoot.class
{webapp_directory}\menu-app\WEB-INF\classes\ HMContentTreeItem.class
{webapp_directory}\menu-app\WEB-INF\classes\ MenuContentBuilder.class

If you are using tomcat, webapp_directory is tomcat’s webapps directory, and menu-app is the Web application directory containing JSP, HTML, JavaScript and class files.

Below is the listing for a menu JSP that adds the dynamic generation of the menu contents and substitutes the static HM_Arrays.js.

<%@ page language="java"  buffer="32kb"%>
<%
       //MenuContentBuilder is the java class that builds the menu tree content
      HMContentTree menuContentTree = MenuContentBuilder.getTree(“Paulo”);
      String menuContent = menuContentTree. toHMContent();
%>
<html>
<head>
 <script language="javascript">
<% out.write(menuContent); %>
</script>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
if(window.event + "" == "undefined") event = null;
function HM_f_PopUp(){return false;};
function HM_f_PopDown(){return false};
popUp = HM_f_PopUp;
popDown = HM_f_PopDown;
HM_a_TreesToBuild = [1];
//-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript1.2" SRC="js/HM_Loader.js" TYPE='text/javascript'></SCRIPT>
</head>
<body>
  <a href="#" 
    onClick="return false;" 
    onMouseOver = "popUp('HM_Menu1',event)" 
    onMouseOut = "popDown('HM_Menu1')"><b>Please bring your mouse over here</b></a>&gt;
  <IMG src="tri.gif" width=7>
</body>
</html>

In the listed JSP code, the generation of the menu contents in the proper format happens in two places:

  1. HMContentTree menuContentTree = MenuContentBuilder.getTree("Paulo");
    MenuContentBuilder constructs the HMContentTree object based on the user parameter. The MenuContentBuilder class can access a database, EJB or some other data source for retrieving the user specific menu content.

  2. String menuContent = menuContentTree.toHMContent();
    The menu contents are generated in the menuContent string. HMContentTree is provided with the toHMContent() method, which navigates the tree structure and generates the proper representation as in the HM_Arrays.js in the HierMenus distribution.

  3. out.write(menuContent);
    The menuContent string is written to the output stream.

Conclusion

This article provides you with listings for HMContentTree, HMContentTreeRoot, HMContentTreeItem and a sample MenuContentBuilder class. It also presents menu.jsp, which brings the content dynamism obtained through these Java classes into the existing HierMenus JavaScript files.

About the authors

Paulo Caroli, www.caroli.org, MSc in Software Engineer, is a Senior Java Developer with more than 8 years of experience in Application Development. He is an expert in Object Oriented techniques and has been using J2EE in Web Applications for the past 4 years. He currently works for OmniPros (www.omnipros.com).

Srimant Misra is a Senior Consultant with 6 years of experience in Information Technology. He's an expert in OOAD and performance monitoring of J2EE applications. He currently works for eTouch Systems (www.etouch.net).


home / programming / java / jspmenus To page 1To page 2To page 3current page
[previous]


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS · Sending an HTML and Plain Text E-newsletter with ASP.NET, Part 2
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
ANSI SQL Hierarchical Data Processing Basics · Top 10 Threats to Wireless Security · Nuvio Intros NuvioFlex Virtual PBX

Created: November 13, 2002
Revised: November 13, 2002

URL: http://webreference.com/programming/java/jspmenus/4.html