A set of custom label of a dynamic menu: Prabu Arumugam
2003/04/09
The menu is an important component of the software application. Realizing static menus relatively simple - only one-time custom classification and functionality can be required. For a dynamic menu, because each user's data and parameters are not the same, it is true that it is more challenging and very tricky.
The Java programming has built-in architecture that creates the basic menu, and JSP lacks this support. Web applications must use Java Applets or JavaScript to implement the menu structure. Many web application developers prefer JavaScript (it is more easily developed than Applets). This article will tell a custom label library that simplifies the generation of dynamic JavaScript processes, including the design and implementation of the label library.
Design
Our design goal is an object model that enables rank classification, including methods of generating JavaScript.
In a menu system for level categories, each menu includes one or more menu items or submenus, and the submenu can also expand include menu items and submenus. The menu provides an entry for implementing the detailed functionality. Regardless of the type of menu, the menu object should produce appropriate JavaScript.
In the composite-based design mode, the Simple Menu implements a menu at the leaf level, and the Composite Menu implements the submenu group and Simple Menu on the menu architecture. In other words: Composite can contain a list of SimpleMenu objects and other CompositeMenu objects. The Menu abstraction declares MENU, defines the render method for supplied subscience to provide their respective implementation.
The following figure depicts the design pattern of this complex:
UML map of the menu class
SimpleMenu implements a URL menu item that points to each application function. CompositeMenu rewrites the render method by looping the submenu list, and each render method is called. Remember, the list may have both menu items, and submenu, so there may be multiple layers.
The following list shows the Render method of CompositeMenu and SimpleMenu. Both methods produce JavaScript, call the method of DynamicMenu.js. The method of this file is responsible for generating a menu in the browser species. The design and implementation of these functions are not within the scope of this article.
SIMPLEMENU RENDER method
StringBuffer SB = new stringbuffer ();
Sb.append ("AddMenuItem (");
Sb.append ("/" getLevelcoord () "/", ");
sb.append ("/" getmenuname () "/", ");
sb.append ("/" geturl () "/", ");
Sb.append ("/" black / ", /" faebd7 / ", /" white / ", /" 3366cc / ", /" white / ",
/ "3366cc /", / "font-family: Tahoma, Verdana, Arial
Font-size: 12px; font-weight: Normal, Text-Decoration: none; padding: 4px / ");");
sb.append ("/ n");
Return sb.toString ();
CompositeMenu's render method
StringBuffer SB = new stringbuffer ();
Sb.append ("AddMenuItem ("); sb.append ("/" getLetlevelcoord () "/", ")
sb.append ("/" getmenuname () "/", ");
IF (null == getURL ())
Sb.append ("NULL" ",");
Else
sb.append ("/" geturl () "/", ");
Sb.append ("/" black / ", /" waebd7 / ", /" white / ", /" 3366cc / ", /" white / ", /" 3366cc / ",
/ "Font-Family: Tahoma, Verdana, Arial; Font-size: 12px;
FONT-Weight: Normal, Text-Decoration: None; Padding: 4px / ");");
sb.append ("/ n");
Iterator it = list.iterator ();
INT i = 1;
While (it.hasnext ())
{
Menu Menu = (MENU) it.next ();
Menu.Setlevelcoord (Getlevelcoord () "," i);
sb.append (menu.render ());
i ;
}
Return sb.toString ();
Menu data source
Menu Builder is responsible for creating a menu based on the data source. The menu data is based on the type. It can be from any source that supports formal data. We implemented the founder, using two universal data sources: XML and databases. Of course, you can easily develop other creators based on this design method.
XMLMenUBuilder
Since the menu structure and the XML structure are enabled by level properties, XML is convenient to express menu data. XMLMenUBuilder accepts XML files that contains menu, parse XML documents to create dynamic menus. The