﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Robin's Java World-随笔分类-翻译</title><link>http://www.blogjava.net/fastzch/category/5342.html</link><description>I Love Java As My Life!</description><language>zh-cn</language><lastBuildDate>Wed, 28 Feb 2007 05:54:04 GMT</lastBuildDate><pubDate>Wed, 28 Feb 2007 05:54:04 GMT</pubDate><ttl>60</ttl><item><title>［译］Struts Menu开发向导</title><link>http://www.blogjava.net/fastzch/archive/2005/11/28/21615.html</link><dc:creator>Robin's Java World</dc:creator><author>Robin's Java World</author><pubDate>Mon, 28 Nov 2005 02:15:00 GMT</pubDate><guid>http://www.blogjava.net/fastzch/archive/2005/11/28/21615.html</guid><wfw:comment>http://www.blogjava.net/fastzch/comments/21615.html</wfw:comment><comments>http://www.blogjava.net/fastzch/archive/2005/11/28/21615.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/fastzch/comments/commentRss/21615.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/fastzch/services/trackbacks/21615.html</trackback:ping><description><![CDATA[<SPAN id=zoom>&nbsp;官方英文版向导（<A href="http://struts-menu.sourceforge.net/userguide.html"><A href="http://struts-menu.sourceforge.net/userguide.html" target=_blank><FONT color=#666666>http://struts-menu.sourceforge.net/userguide.html</FONT></A></A>）
<P>一、从1.X升级到2.X需要做以下事情：<BR>1、改变你的taglib声明中的URI。<BR><FONT style="BACKGROUND-COLOR: #ffe000">&nbsp;&lt;% at taglib uri="</FONT><A href="http://struts-menu%20dot%20sf.net/tag"><FONT style="BACKGROUND-COLOR: #ffe000"><A href="http://struts-menu.sf.net/tag" target=_blank><FONT color=#666666>http://struts-menu.sf.net/tag</FONT></A></FONT></A><FONT style="BACKGROUND-COLOR: #ffe000">" prefix="menu" %&gt;<BR></FONT>2、改变&lt;plug-in&gt;,使用新的包名"net.sf.navigator." 。<BR>&nbsp;<FONT style="BACKGROUND-COLOR: #ffe000">&lt;plug-in className="net.sf.navigator.menu.MenuPlugIn"&gt;</FONT><BR>3、改变你的menu-config.xml文件，使用新的包名"net.sf.navigator." 。<BR><FONT style="BACKGROUND-COLOR: #ffe000">&nbsp;&lt;Displayer name="Simple"<BR>&nbsp;&nbsp; type="net.sf.navigator.displayer.SimpleMenuDisplayer"/&gt;</FONT></P>
<P>二、快速开始：<BR>1、下载最新的struts-menu版本；<BR>2、解包到本地目录；<BR>3、下载Tomcat或者其它Servlet容器；<BR>4、把struts-menu.war包放入Tomcat安装目录的wabapps目录下，并重启Tomcat服务。<BR>5、打开htpp://localhost:8080/struts-menu/</P>
<P>三、把Struts Menu整合到你的应用程序中：<BR>Struts Menu能够被轻易的整合到你的Struts应用程序中，它也可以整合到一个非Struts的应用程序中，但是我不喜欢这样做，所以在此没有提供相应的教程。这里将一步步的带你整合这个标签库。<BR>你需要把struts-menu.jar放到你的WEB-INF/lib目录下。然后使用URI标签声明你的JSP文件中想使用的这个标签库。<BR>如果使用Struts Menu 2.1，你还需要 Jakarta's Standard Tag Library JAR包放入你的WEB-INF/lib目录下。下载地址：<A href="http://ibiblio.org/maven/taglibs/jars/standard-1.0.4.jar"><A href="http://ibiblio.org/maven/taglibs/jars/standard-1.0.4.jar" target=_blank><FONT color=#666666>http://ibiblio.org/maven/taglibs/jars/standard-1.0.4.jar</FONT></A></A>，这个文件包括例程WAR包文件和二进制发布包。<BR>1、放入struts-menu.jar包到你的应用程序的WEB-INF/lib目录中。<BR>2、在你的struts-config.xml文件中加入plug-in设置。<BR><FONT style="BACKGROUND-COLOR: #ffe000">&nbsp;&lt;plug-in className="net.sf.navigator.menu.MenuPlugIn"&gt;<BR>&nbsp;&nbsp; &lt;set-property property="menuConfig"<BR>&nbsp;&nbsp;&nbsp;&nbsp; value="/WEB-INF/menu-config.xml"/&gt;<BR>&nbsp;&lt;/plug-in&gt;</FONT><BR>3、你将需要在你的应用程序的/WEB-INF/menu-config.xml文件中定义你的菜单，这里提供一个简单的片断：<BR><FONT style="BACKGROUND-COLOR: #ffe000">&nbsp;&lt;Menu name="contactMenu" title="Contact" location="?Contact"&gt;<BR>&nbsp;&nbsp; &lt;Item name="email" title="E-Mail" location="?EMail"/&gt;<BR>&nbsp;&nbsp; &lt;Item name="phone" title="Phone" location="?Phone"/&gt;<BR>&nbsp;&lt;/Menu&gt;</FONT><BR>　　更多全面的例程，请查看应用程序的web/WEB-INF目录中的menu-config.xml文件，你可以截取一段作为你需要的菜单。完整的属性列表，可以查看MenuBase class's javadocs（<A href="http://struts-menu.sourceforge.net/apidocs/net/sf/navigator/menu/MenuBase.html"><A href="http://struts-menu.sourceforge.net/apidocs/net/sf/navigator/menu/MenuBase.html" target=_blank><FONT color=#666666>http://struts-menu.source......avigator/menu/MenuBase.html</FONT></A></A>）。<BR>4、在你的JSP文件的顶部加入taglib声明：<BR>&nbsp;<FONT style="BACKGROUND-COLOR: #ffe000">&lt;% at taglib uri="</FONT><A href="http://struts-menu%20dot%20sf.net/tag"><FONT style="BACKGROUND-COLOR: #ffe000"><A href="http://struts-menu.sf.net/tag" target=_blank><FONT color=#666666>http://struts-menu.sf.net/tag</FONT></A></FONT></A><FONT style="BACKGROUND-COLOR: #ffe000">" prefix="menu" %&gt;</FONT><BR>5、在你的JSP文件中要放置菜单的位置加入taglib代码：<BR><FONT style="BACKGROUND-COLOR: #ffe000">&nbsp;&lt;menu:useMenuDisplayer name="TabbedMenu"<BR>&nbsp;&nbsp; bundle="org.apache.struts.action.MESSAGE"&gt;<BR>&nbsp;&nbsp; &lt;menu:displayMenu name="Home"/&gt;<BR>&nbsp;&nbsp; &lt;menu:displayMenu name="About"/&gt;<BR>&nbsp;&lt;/menu:useMenuDisplayer&gt;</FONT><BR>　　属性name="TabbedMenu"被定义在menu-config.xml文件的顶部：<BR><FONT style="BACKGROUND-COLOR: #ffe000">&nbsp;&lt;Displayer name="TabbedMenu"<BR>&nbsp;&nbsp; type="net.sf.navigator.displayer.TabbedMenuDisplayer"/&gt;</FONT></P>
<P><FONT style="BACKGROUND-COLOR: #a0ff00">(译注：其实到此步即可在你的JSP文件中添加相应的菜单了，只不过是没有结合Velocity。在menu-config.xml文件的头部可以定义多个Displayer，每个Displayer都有name和type属性，name属性与JSP文件中menu:useMenuDisplayer标签的name属性相对应，即表明使用何种样式，具体的样式定义便在type属性中定义，type属性中是一个class。在menu-config.xml文件中的菜单定义中的name属性则与JSP文件中的menu:displayMenu标签的name属性相对应。)</FONT></P>
<P>使用定制的Velocity模版实施你的菜单，你需要整合Velocity到你的WEB应用程序中。如果需要这样做的话，请完成下面的步骤：<BR>1、确定你的menu-config.xml文件有“Velocity”的displayer定义：<BR><FONT style="BACKGROUND-COLOR: #ffe000">&nbsp;&lt;Displayer name="Velocity" <BR>&nbsp;&nbsp;&nbsp;&nbsp; type="net.sf.navigator.displayer.VelocityMenuDisplayer"/&gt;</FONT><BR>2、加入Velocity的JARs包到你的WEB-INF/lib目录中，下载velocity-1.4-rc1.jar（<A href="http://www.ibiblio.org/maven/velocity/jars/velocity-1.4-rc1.jar"><A href="http://www.ibiblio.org/maven/velocity/jars/velocity-1.4-rc1.jar" target=_blank><FONT color=#666666>http://www.ibiblio.org/ma......y/jars/velocity-1.4-rc1.jar</FONT></A></A>）和velocity-tools-view-1.0.jar（<A href="http://www.ibiblio.org/maven/velocity-tools/jars/velocity-tools-view-1.0.jar"><A href="http://www.ibiblio.org/maven/velocity-tools/jars/velocity-tools-view-1.0.jar" target=_blank><FONT color=#666666>http://www.ibiblio.org/ma......velocity-tools-view-1.0.jar</FONT></A></A>）。 <BR>3、加入globalMacros.vm（<A href="http://cvs.sourceforge.net/viewcvs.py/*checkout*/struts-menu/navigator/web/WEB-INF/classes/globalMacros.vm?content-type=text%2Fplain&amp;rev=1.1"><A href="http://cvs.sourceforge.net/viewcvs.py/" target=_blank><FONT color=#666666>http://cvs.sourceforge.net/viewcvs.py/</FONT></A>*checkout*/struts-menu/navigator/web/WEB-INF/classes/globalMacros.vm?content-type=text%2Fplain&amp;rev=1.1</A>（右键另存为））到你的WEB-INF/lib目录中。<BR>4、改变你的JSP文件中displayer的值为“Velocity”，“config”属性指向一个文件（如config="/templates/tabs.html"）或者如果tabs.htm在你的WEB-INF/classes目录中的话，则可设config="tabs.html"。</P>
<P>这里提供了一些使用Velocity的displayer例子，可在sample application（<A href="http://demo.raibledesigns.com/struts-menu/index.jsp"><A href="http://demo.raibledesigns.com/struts-menu/index.jsp" target=_blank><FONT color=#666666>http://demo.raibledesigns.com/struts-menu/index.jsp</FONT></A></A>）中查看。它总是在你的菜单需要的时候显示CSS，JavaScript和图像文件。下面有一些在当前的Struts Menu中用到的Velocity模版的例子的链接：<BR>&nbsp;CoolMenus: Demo（<A href="http://demo.raibledesigns.com/struts-menu/velocity-coolmenu4.jsp"><A href="http://demo.raibledesigns.com/struts-menu/velocity-coolmenu4.jsp" target=_blank><FONT color=#666666>http://demo.raibledesigns......menu/velocity-coolmenu4.jsp</FONT></A></A>）, <BR>&nbsp;&nbsp;　 Template（<A href="http://struts-menu.sourceforge.net/templates/coolmenus.html"><A href="http://struts-menu.sourceforge.net/templates/coolmenus.html" target=_blank><FONT color=#666666>http://struts-menu.sourceforge.net/templates/coolmenus.html</FONT></A></A>） <BR>&nbsp;NiceTabs: Demo, Template <BR>&nbsp;Tabs: Demo, Template <BR>&nbsp;XTree: Demo, Template </P>
<P>所有相关的有用的文件如果你需要的话都可以在下面的站点上下载：<BR>&nbsp;Images （<A href="http://struts-menu.sourceforge.net/menu-images/"><A href="http://struts-menu.sourceforge.net/menu-images/" target=_blank><FONT color=#666666>http://struts-menu.sourceforge.net/menu-images/</FONT></A></A>）<BR>&nbsp;Stylesheets （<A href="http://struts-menu.sourceforge.net/styles/"><A href="http://struts-menu.sourceforge.net/styles/" target=_blank><FONT color=#666666>http://struts-menu.sourceforge.net/styles/</FONT></A></A>）<BR>&nbsp;Scripts （<A href="http://struts-menu.sourceforge.net/scripts/"><A href="http://struts-menu.sourceforge.net/scripts/" target=_blank><FONT color=#666666>http://struts-menu.sourceforge.net/scripts/</FONT></A></A>）<BR>&nbsp;Templates （<A href="http://struts-menu.sourceforge.net/templates/"><A href="http://struts-menu.sourceforge.net/templates/" target=_blank><FONT color=#666666>http://struts-menu.sourceforge.net/templates/</FONT></A></A>）</P>
<P>更多的基于roles的显示/隐藏菜单的信息，请查看FAQs（<A href="http://struts-menu.sourceforge.net/faq.html"><A href="http://struts-menu.sourceforge.net/faq.html" target=_blank><FONT color=#666666>http://struts-menu.sourceforge.net/faq.html</FONT></A></A>）。</P>
<P>四、在Struts之外使用Struts Menu:<BR>在2.2版中，Menu Repository能够使用MenuContextListener载入：<BR><FONT style="BACKGROUND-COLOR: #ffe000">&nbsp;&lt;!--<BR>&nbsp;&nbsp;&nbsp; - Loads the menu-config.xml for struts-menu at startup,<BR>&nbsp;&nbsp;&nbsp; - by default from "/WEB-INF/menu-config.xml".<BR>&nbsp;&nbsp;&nbsp; - To override this, add a context-param named "menuConfigLocation"<BR>&nbsp;&nbsp;&nbsp; - web.xml file.<BR>&nbsp;&nbsp;&nbsp; --&gt;<BR>&nbsp;&lt;listener&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp; &lt;listener-class&gt;net.sf.navigator.menu.MenuContextListener&lt;/listener-class&gt;<BR>&nbsp;&lt;/listener&gt;</FONT></P>
<P>或者如果你使用Spring，甚至更容易。仅仅需要加入下面的部分到你的applicationContext.xml文件中：<BR><FONT style="BACKGROUND-COLOR: #ffe000">&nbsp;&lt;bean id="menu" class="net.sf.navigator.menu.MenuLoader"&gt;<BR>&nbsp;&nbsp; &lt;property name="menuConfig"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp; &lt;value&gt;/WEB-INF/menu-config.xml&lt;/value&gt;<BR>&nbsp;&nbsp; &lt;/property&gt;<BR>&nbsp;&lt;/bean&gt;<BR>&nbsp;&lt;!-- The menuConfig property is an optional attribute.&nbsp; It is set to<BR>&nbsp;&nbsp;&nbsp;&nbsp; /WEB-INF/menu-config.xml by default. --&gt;</FONT><BR>感谢Dan Luputan提供MenuLoader类的源代码。</P>
<P>五、从源文件编译：<BR>要从源文件编译这个项目，执行下面的步骤：<BR>1、下载并安装Maven（<A href="http://maven.apache.org/"><A href="http://maven.apache.org/" target=_blank><FONT color=#666666>http://maven.apache.org/</FONT></A></A>）；<BR>2、创建一个环境变量MAVEN＿HOME指出你的Maven的安装目录，然后添加$MAVEN_HOME/bin到你的PATH变量中；<BR>3、操纵这个目录你可以扩展源代码，执行“maven.jar”创建target/struts-menu.jar。</P>
<P>要展开struts-menu例程，需要下面的步骤：<BR>1、下载和安装Tomcat；<BR>2、创建一个环境变量CATALINA＿HOME指出你的Tomcat的安装目录；<BR>3、执行“maven deploy”把应用程序展开到Tomcat中；<BR>4、打开<A href="http://localhost:8080/struts-menu"><A href="http://localhost:8080/struts-menu" target=_blank><FONT color=#666666>http://localhost:8080/struts-menu</FONT></A></A>在你喜爱的浏览器中。</P>
<P>如果你喜欢使用Eclipse开发项目，请参考此份开发向导（<A href="http://struts-menu.sourceforge.net/devguide.html"><A href="http://struts-menu.sourceforge.net/devguide.html" target=_blank><FONT color=#666666>http://struts-menu.sourceforge.net/devguide.html</FONT></A></A>）。 </P></SPAN><img src ="http://www.blogjava.net/fastzch/aggbug/21615.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/fastzch/" target="_blank">Robin's Java World</a> 2005-11-28 10:15 <a href="http://www.blogjava.net/fastzch/archive/2005/11/28/21615.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>