在企业应用中一般需要根据登录用户的身份动态生成系统菜单,本文演示了使用Smooth Navigational Menu插件,通过ajax技术,从后台获取数据动态生成菜单的方法。其中前台使用的Smooth Navigational Menu是一jquery插件,后台使用Struts的Action与其交互。
Smooth Navigational Menu的主页为:http://www.dynamicdrive.com/dynamicindex1/ddsmoothmenu.htm
将jquery和Smooth Navigational Menu引入项目很简单,只需将有关文件拷贝到 WebContent 目录下即可,本例中以如下结构引入:
/WebContent
/jquery jquery-1.3.1.js
/smoothmenu ddsmoothmenu.css, ddsmoothmenu.js, down.gif, right.gif
jsp文件中引入相关的css和js文件,并定义容纳菜单的<div>,代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jquery web app</title>
<link rel="stylesheet" type="text/css" href="jquery/smoothmenu/ddsmoothmenu.css" />
<script type="text/javascript" src="jquery/jquery-1.3.1.js"></script>
<script type="text/javascript" src="jquery/smoothmenu/ddsmoothmenu.js"></script>
</head>
<body>
<div id="smoothcontainer">
</div>
</body>
</html>
为了以ajax方式获取数据,需要修改ddsmoothmenu.js。修改的位置为文件末尾处的ddsmoothmenu.init( )处,代码如下:
ddsmoothmenu.init({
mainmenuid: "smoothmenu-ajax", //菜单的id
customtheme: ["#1c5a80", "#18374a"], //颜色定义
contentsource: ["smoothcontainer", "GetMenuAction.action"] //容纳菜单的<div>的id,获取菜单数据的url
})
其中mainmenuid是菜单数据中菜单<div>的id,这在后面的Action处可以看到,contentsource的第一项是jsp中容纳菜单的<div>的id,第二项是通过ajax获取菜单数据的url
另外,为了正确显示菜单中的箭头,需要修改ddsmoothmenu.js中down.gif和right.gif的路径。
示例的Action代码如下,其中的菜单数据可以想象为例如从数据库读取的。
package jqweb.actions;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import com.opensymphony.xwork2.ActionSupport;
public class MenuAction extends ActionSupport {
private static final long serialVersionUID = -7891855010840306865L;
private InputStream inputStream;
public void setInputStream(InputStream inputStream) {
this.inputStream = inputStream;
}
public InputStream getInputStream() {
return inputStream;
}
public String execute() throws Exception {
StringBuilder sb = new StringBuilder();
sb.append("<div id='smoothmenu-ajax' class='ddsmoothmenu'>");
sb.append("<ul>");
sb.append("<li><a href='#'>菜单1</a>");
sb.append(" <ul>");
sb.append(" <li><a href='http://www.google.con'>谷歌中国</a></li>");
sb.append(" <li><a href='http://www.baidu.com'>百度</a></li>");
sb.append(" </ul>");
sb.append("</li>");
sb.append("<li><a href='#'>菜单2</a>");
sb.append(" <ul>");
sb.append(" <li><a href='http://www.google.con'>谷歌中国</a></li>");
sb.append(" <li><a href='#'>菜单2.1</a>");
sb.append(" <ul>");
sb.append(" <li><a href='#'>菜单2.1.1</a></li>");
sb.append(" <li><a href='#'>菜单2.1.2</a></li>");
sb.append(" <li><a href='#'>菜单2.1.3</a></li>");
sb.append(" </ul>");
sb.append(" </li>");
sb.append(" </ul>");
sb.append("</li>");
sb.append("</ul>");
sb.append("<br style='clear: left' />");
sb.append("</div>");
inputStream = new ByteArrayInputStream(sb.toString().getBytes("utf-8"));
return SUCCESS;
}
}
struts.xml中对这个action的定义与一般的action不同,定义如下:
<action name="GetMenuAction" class="jqweb.actions.MenuAction">
<result type="stream">
<param name="contentType">text/html</param>
<param name="inputName">inputStream</param>
</result>
</action>
最后实现的菜单效果如下:
- 大小: 8.9 KB
分享到:
- 2009-02-10 14:34
- 浏览 1375
- 评论(0)
- 论坛回复 / 浏览 (0 / 4704)
- 查看更多
相关推荐
jquery 导航栏 Smooth Navigational Menu
timers定时器实现javascrip定时或按钮控制功能 ...SmoothNavigationalMenu导航菜单实现Javascript下拉多级菜单功能 ImageFlyout弹出图片实现javascript放大图片功能 accordion折叠菜单实现Javascript展开收缩菜单功能
网上找了很久这种菜单,浪费了很多时间,实在没办法,只好老老实实去官网上按说明弄了一个,并更新了,jquery1.5.2, 希望给有需要的朋友可以节约一点时间,欢迎交流,qq:170262
导航菜单(TBA) HTML和CSS多层导航菜单
使用场景图将复杂导航指令接地_Grounding Complex Navigational Instructions Using Scene Graphs.pdf
Office 2003 style toolbar, planning/scheduling components, advanced edits, toolbars, internet auto application update, Office 2003/2007 style tabs, pager, panel, Outlook navigational controls and ...
Waypoints顶部导航栏是一款基于jquery实现的粘性的顶部导航栏插件。
-天体导航:降低视线,定位线,固定...-位置天文学:航海年历,RA,GHA,12月-沿海导航:范围,白令,水平角,IALA ...-航行:大WaSP,恶臭,正畸,子午线...-天气,潮汐-软件:PC,Android ...
最新海道测量数据传输标准S-100,后续,S-57将会肯定逐渐地被S-100所替代
*The navigational menu is dynamically updated based on the number of sections that is added to the page. *Each section is set to active class when it's selected from the navigation menu items or ...
New navigational controls – TreeView 新的导航控件-TreeView New login controls – Login, PasswordRecovery, LoginName and LoginStatus 新的登录控件-Login,PasswordRecovery,LoginName和LoginStatus Web ...
更新说明(Some features):Support for Custom Post Types Advanced Canonical URLs Fine tune Page Navigational Links Built-in API so other plugins/themes can access and extend functionality ONLY plugin ...
Office 2003 style toolbar, planning/scheduling components, advanced edits, toolbars, internet auto application update, Office 2003/2007 style tabs, pager, panel, Outlook navigational controls and ...
推荐系统是电子商务中的一种策略,它根据... 实验是用已实现的系统进行的,并与传统系统进行了比较。 系统在精度、召回率和内存消耗方面的比较性能研究表明,与可用的传统数据模型相比,所提出的技术是有效和准确的。
Office 2003 style toolbar, planning/scheduling components, advanced edits, toolbars, internet auto application update, Office 2003/2007 style tabs, pager, panel, Outlook navigational controls and ...
There are some new API calls to handle requests for facilities data (airports, navigational aids and waypoints) and on-screen text and menus (similar to the existing modeless ATC menus), and two new ...
来源于俄罗斯网站。TMS Component Pack v6.9.3.0 for Delphi & C++Builder 5-XE4 Full Sources ... Office 2003/2007 style tabs, pager, panel, Outlook navigational controls and much much more
This document was prepared as a summary and a navigational tool for HB 292, A practitioners guide to business continuity management, and the structure is based on the framework of HB 221 Business ...
4 publication and references the internationally agreed-on product specification for symbols, abbreviations, and terms used on hard-copy navigational charts.