Custom label for a set of dynamic menus

xiaoxiao2021-03-06  58

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

element of the XML document can be seen as a menu item or submenu, and the submenu can also expand including a menu item or submenu.

JDBCMenUBuilder

Since the database table can represent the associated data, the table can also be used to express rating data. The hierarchymenu table represents the hierarchical menu data. JDBCMenUBuilder accepts information from the database and selects menu data from the hierarchymenu table according to the order.

Menu label library

Menu Tag Library Management Creates the complex process of the JavaScript menu. The menu label itself is an abstract class that inherits the Tagsupport class and rewrites the DostartTAG and DOENDTAG methods. The GetMenu method is an abstract method to rewrite the subclass to provide JavaScript, which can increase the menu item of the menu structure created in the dostartTAG method. The subclass of the menu tag rewrites the GetMenu method, using a menu creation that can extract menu data from the data source.

One of the dynamic menu tag libraries contains two tags: JDBCMenutag and XMLMenutag. JDBCMENUTAG uses JDBCBuilder to create a menu structure according to data in the database, while XMLMenutag uses XMLBuilder to create a menu structure according to XML data sources. Documentation provides detailed descriptions of label libraries.

This version of the label library also contains some limitations. It does not make user roles and menus that are associated, each app is different. The label library does not provide support for menu item specific colors and fonts. Menu label library application example

The Menu-Example.war file contains the JSP page using the tag library. Deploy the application in Tomcat:

(1) Copy Menu-Example.wAR to Tomcat Install Folder / WebApps.

(2) Restart Tomcat to expand the application.

(3) Adjust XMLMenu.jsp and JDBCMenu.jsp According to the environment

(4) Create a new database table structure to import the data in the menu.sql file.

(5) Access the menu created according to XML, access localhost: 8080 / menu-example / xmlmenu.jsp.

(6) Access to create a large amount menu according to JDBC, access localhost: 8080 / menu-example / jdbcmenu.jsp.

in conclusion

Dynamic Menu Tag Library Authority creates a complex process of the menu via JavaScript and allows web applications to create a dynamic level menu through a database or XML source.

[b] Resources / B]

For more information on menu tag libraries, please visit Menutag.html Documents

• Design Mode, Eric Gamma, Richard Helm, Ralph Johnson, John Vlissides (Addison-Wesley Publishing Co., 1995; ISBN: 0201633612)

• JSP Tag Libraries:

http://java.sun.com/products/jsp/taglibralies.html

Related download:

• Menu.zip:

http://www.onjava.com/onjava/2003/04/09/examples/menu.zip

• Menu-Example.war:

http://www.onjava.com/onjava/2003/04/09/examples/menu-example.war

Menu Tag Library Using Documentation

http://www.onjava.com/onjava/2003/04/09/examples/Menutag.html

Prabu arumugam is a software architect and advanced Java developer, working on Forest Express, LLC.

转载请注明原文地址:https://www.9cbs.com/read-114600.html

New Post(0)