struts-menu的target问题

来源:互联网 发布:怎么做好网络咨询护士 编辑:程序博客网 时间:2024/04/29 06:48

struts-menu中使用XtreeMenu或者VelocityMenuDisplayer的target问题

 

方案一:可解决VelocityMenuDisplayer问题:修改模板/templates/xtree.html

显示用到javascript,用到javascript文件不同(列:xtree,xloadtree)只是显示样子不同,当然要用到menu_table其他字段值可以自己添加列

红色部分为增加部分

 

## displayMenu is defined in WEB-INF/classes/globalMacros.vm

#macro( menuItem $menu $level )

## set title

#set ($title = $displayer.getMessage($menu.title))

#set ($node = $menu.name)

#if ($level == 0)

var $node = new WebFXTree('$title'#if($menu.url),'$!menu.url'#end);

#else

var $node = new WebFXTreeItem('$title'#if($menu.url),'$!menu.url'#end);

#if($menu.target)${node}.target='$menu.target';#end

${menu.parent.name}.add($node);

#end

#end

#displayMenu($menu 0)

document.write($menu.name);

 

 

 

方案二:可解决XtreeMenuVelocityMenuDisplayer问题

我们点击树的一个节点,会在main页面中显示返回的页面。这是通过设置超链接的 target="main"来实现的。
在struts-menu里,你如果使用  DropDownMenuDisplayer,可以设置menu的target属性,但是如果你使VelocityMenuDisplayer显示,设置target属性是不会起作用的。因为真正实现显示的是scripts/xtree.js,而xtree.js会对menu设置的target视而不见,可以通过修改xtree.js的代码来设置target了。

红色部分为增加部分在WebFXTreeAbstractNode的定义中,增加了一个target属性:Main是显示结果frame的名字。


function WebFXTreeAbstractNode(sText, sAction) {
 this.childNodes  = [];
 this.id     = webFXTreeHandler.getId();
 this.text   = sText || webFXTreeConfig.defaultText;
 this.action = sAction || webFXTreeConfig.defaultAction;
 this._last  = false;
 
this.target = "Main";
 webFXTreeHandler.all[this.id] = this;
}

 

方案三:此方案未测试过,也不推荐使用,看源码只在ListMenuDisplayer用到,而ListMenuDisplayer的target属性本来就有用

修改struts-menu源码中的:     DisplayerStrings.properties   然后编译就行了.

红色部分为增加部分,你自已可以设置该target值,设置成自已想将struts-menu中的菜单点开后,需要在哪个frame中展开. 

 

 

#starts the top level of the menu
dd.menu.top=<table width/="150" style/="background-color/:lightgrey" cellpadding/=1 cellspacing/=1><tr align/=left><td nowrap class/=normal><b>
dd.menu.bottom=</td></tr></table>
dd.image.src.expand=/public/resources/menu/images/Rarrow.gif
dd.link.start=<a href/="{0}" target/="{1}" title/="{2}" style/="text-decoration/:none;font-family/:Helvetica,Arial;font-size/:12px">
dd.link.end=</a>
dd.js.toggle.display=   function toggleMenuDisplay(menu, img) {0}/n  var cookieName /= "menu-" + menu.id;/n  if (menu.style.display /=/= 'none') {0}/n    menu.style.display/='block';/n    img.src /= imgSrcExpanded;/n    setCookie(cookieName,'block');  /n  {1} else{0}/n    menu.style.display/='none';/n    img.src /= imgSrcExpand;/n    setCookie(cookieName,'none');  {1}/n{1}
dd.js.start=/n<script type/="text/javascript">/n
dd.js.end=/n</script>
#area on the document that toggles the display of the associated menu
dd.menu.expander=<label style/="cursor/:hand;font-family/:verdana;font-size/:12px;font-weight/:bold" onmouseover/="this.style.color/='red'" onmouseout/="this.style.color/='black'" onclick/="toggleMenuDisplay(document.getElementById('{0}'), document.getElementById('{1}'))"> {2} </label>
dd.menu.restricted=<label style/="cursor/:hand;font-family/:verdana;font-size/:12px;font-weight/:bold" onmouseover/="this.style.color/='red'" onmouseout/="this.style.color/='black'" onclick/="return false"> {2} </label>
dd.menu.restore=<script type="text/javascript">/n  var redisplay /= getCookie('menu-{0}');/n  if (redisplay /=/= 'block')/n  toggleMenuDisplay(document.getElementById('{0}'), document.getElementById('{1}'), false);/n</script>

#starts a menu item
dd.menu.item.top=<div id/="{0}" style/="display/:none">/n<table cellpadding/="0" cellspacing/="0">/n
dd.menu.item.bottom=</table></div>
dd.menu.item.row.start=<tr><td>&nbsp;&nbsp;
dd.menu.item.row.end=</td></tr>
dd.image=<img src/="{0}" style/="border: 0" />
dd.image.src.expanded=/public/resources/menu/images/Darrow.gif
dd.image.expander=<img id/="{0}" src/="{1}" style/="border: 0" />
dd.js.image.src.expand=  var imgSrcExpand /= "{0}";/n
dd.js.image.src.expanded=  var imgSrcExpanded /= "{0}";/n
smd.style=<style type="text/css">/n  .smd-menu-top {0}font-family:verdana,arial;font-size:12px;font-weight:bold{1}/n  .smd-menu-item {0}font-family:verdana,arial;font-size:12px;{1}/n  img.smd-menu {0}border: 0{1}/n  a.smd-menu {0}text-decoration:none{1}/n</style>
smd.menu.top=<table cellpadding/="0" cellspacing/="1">/n
smd.menu.bottom=</table>/n
smd.menu.item.top=<tr><td class/="smd-menu-top">{0}</td></tr>/n
smd.menu.item=<tr><td class/="smd-menu-item"><a href/="{0}" class/="smd-menu" target/="{1}" title/="{2}">{3}</a></td></tr>/n
smd.menu.item.image=<img src/="{0}" class/="smd-menu"/>&nbsp;
smd.menu.item.image.bullet=


#TODO: add /n and /t's to make it look prettier and mouse event handlers
lmd.js.start=/n<script type="text/javascript">/n<!--/n/twindow.onload = function() {/n
lmd.js=/t/tinitializeMenu("{0}", "{1}");/n
lmd.js.expand=/t/texpandMenus();/n
lmd.js.stop=/t}/n//-->/n</script>
lmd.begin=<ul {0}class="menuList">/n
lmd.end=</ul>
lmd.menu.top=/t<li class="menubar">/n
lmd.menu.bottom=/t</li>/n
lmd.menu.actuator.link=/t<a href="#" id="{0}Actuator" class="actuator">&nbsp;</a><a href="{3}" title="{1}" target ="Main" class="base">{1}</a>/n/t/t<ul id="{0}Menu" class="{2}">/n
lmd.menu.actuator.top=/t<a href="#" id="{0}Actuator" class="actuator">{1}</a>/n/t/t<ul id="{0}Menu" class="{2}">/n
lmd.menu.actuator.bottom=/t/t</ul>/n/t</li>/n
lmd.menu.item=/t<li><a href="{0}" title="{1}"{2}>{3}</a></li>
lmd.menu.standalone=/t<a href="{0}" title="{1}" class="standalone"{2}>{3}</a>

#coolmenus HTML
cm.image=<img src/="{0}" style/="/:none" />

#tabbedmenu HTML
tmd.menu.tab=<a href="{0}" title="{1}"{2}>{3}</a>/n/t<ul class="submenu">/n
tmd.menu.item=/t<li><a href="{0}" title="{1}"{2}>{3}</a></li>

# css list menu
ccslm.menu.top=/t<li{0}>/n
ccslm.menubar.top=/t<a href="{0}"{1}>{2}</a>/n

原创粉丝点击