Raible's Wiki
Raible Designs AppFuseHomepage- Korean - Chinese - Italian - Japanese QuickStart Guide User Guide Tutorials Other ApplicationsStruts ResumeSecurity Example Struts Menu
Set your name in
UserPreferences
Referenced by
JSPWiki v2.2.33
Hide Menu |
This is version 2.
It is not the current version, and thus it cannot be edited. I did some refactorings on Struts Menu in the last few days and thought I'd document them here as it's a bit more convenient than via e-mail. Also, I have a couple issues that might be better exposed here vs. a mailing list. Refactorings:
page="/velocity.jsp?test=${test}In this example, the variable 'test' is searched for using pageContext.findAttribute("test"). You could easily set this parameter using JSTL and <c:set var="test" value="value" />. It probably wouldn't be too hard to add support for request parameters too.
context.put("formatter", new VelocityFormatter(context)); context.put("now", Calendar.getInstance().getTime()); context.put("ctxPath", request.getContextPath()); // see if a name and property were passed in if (!StringUtils.isEmpty(name)) { Object val1 = RequestUtils.lookup(pageContext, name, null, null); if (val1 != null) { context.put(name, val1); } } // request-scope attributes Enumeration enum = request.getAttributeNames(); while (enum.hasMoreElements()) { String name = (String) enum.nextElement(); Object value = request.getAttribute(name); context.put(name, value); } context.put("request", request); context.put("session", request.getSession()); context.put("menu", menu); context.put("displayer", this); Here is a sample velocity template for rendering a simple menu. It shouldn't be too hard to re-create the existing using Velocity templates. ## Evaluates other macros. #macro(eval $_macro)$_macro#end #macro( displayMenu $menu $level ) #if ($menu.components.size() > 0) ## display top menu #menuItem($menu $level) #foreach ($menu in $menu.components) #local ($menu $level) #set ($level = $level+1) #if ($menu.components.size() > 0) #eval("#displayMenu($menu $level)") #else #menuItem($menu $level) #end #end #end #else #menuItem($menu $level) #end #end #macro( menuItem $menu $level ) #foreach ($i in [0..$level]) #end #if ($menu.url) <a href="$menu.url" title="$menu.title"> $menu.title</a> #else $menu.title #end <br /> #end #displayMenu($menu 0) This is configured in your JSP using: <menu:useMenuDisplayer name="Velocity" config="/table.html" bundle="org.apache.struts.action.MESSAGE"> <menu:displayMenu name="indexMenu"/> </menu:useMenuDisplayer> Where config points to a file relative to your webapp. You can also use config="table.html" where table.html is under WEB-INF/classes. TODOs:
Comments, suggestions or questions are most welcome. If not here, doing it on one of the mailing lists is probably most appropriate.
|