| <html><head> |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <title>6.6. Menus</title><link rel="stylesheet" href="css/stylesheet.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.75.0"><link rel="home" href="index.html" title="Apache Click"><link rel="up" href="ch06.html" title="Chapter 6. Best Practices"><link rel="prev" href="ch06s05.html" title="6.5. Templating"><link rel="next" href="ch06s07.html" title="6.7. Logging"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">6.6. Menus</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch06s05.html">Prev</a> </td><th width="60%" align="center">Chapter 6. Best Practices</th><td width="20%" align="right"> <a accesskey="n" href="ch06s07.html">Next</a></td></tr></table><hr></div><div class="sect1" title="6.6. Menus"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="menus"></a>6.6. Menus</h2></div></div></div><p> For many applications using the |
| <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../extras-api/org/apache/click/extras/control/Menu.html" target="_blank">Menu</a> |
| control to centralize application navigation is very useful. Menus are |
| defined in a <code class="filename">WEB-INF/menu.xml</code> file which is very easy to |
| change. |
| </p><p>A menu is typically defined in the a page border template so they are |
| available through out the application. The Menu control does not support HTML |
| rendering, so you need to define a Velocity macro to programmatically render |
| the menu. You would call the macro in your border template with code like this: |
| </p><div class="literallayout"><p><span class="symbol">#</span><code class="varname">writeMenu</code>(<span class="symbol">$</span>rootMenu)</p></div><p>An advantage of using a macro to render your menu is that you can reuse |
| the code across different applications, and to modify an applications menu you |
| simply need to edit the <code class="filename">WEB-INF/menu.xml</code> file. A good |
| place to define your macros is in the webroot <code class="filename">/macro.vm</code> |
| file as it is automatically included by Click. |
| </p><p>Using macros you can create dynamic menu behaviour such as only rendering |
| menu items a user is authorized to access with |
| <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../extras-api/org/apache/click/extras/control/Menu.html#isUserInRoles()" target="_blank">isUserInRoles()</a>. |
| </p><div class="literallayout"><p><span class="command"><strong>#if</strong></span> (<span class="symbol">$</span>menu.isUserInRoles())<br> |
| ..<br> |
| <span class="command"><strong>#end</strong></span></p></div><p>You can also use JavaScript to add dynamic behaviour such as drop down menus, |
| for example see the Menu page in Click |
| <a xmlns:fo="http://www.w3.org/1999/XSL/Format" class="external" href="../../examples.html" target="_blank">Examples</a>. |
| </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch06s05.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch06.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch06s07.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">6.5. Templating </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 6.7. Logging</td></tr></table></div></body></html> |