Looking to build a generic context-sensitive menu using WebWork. Came up with the following requirements:
- All items described below are menu elements.
- A menu element has a name attribute.
- A menu element has a parent menu element.
- If a menu element does not have a parent, it is the root menu.
- A menu element is only aware of its structural representation, i.e.: it’s a model.
- A menu may be composed of other menus.
- There is only one root menu.
- The root menu has a default menu set.
- The default menu is shown if the current use case does not provide a menu.
- There is a mechanism to change the current menu based on the current use case.
- A menu may have child menu items.
- A menu item has an action attribute. The view will rely on this to react to a menu item being selected or clicked. This action may be a URL or script call.
The visual representation of the menu elements above could be as simple (html) or complex (Ajax/DHTML) as the end user wants. As a default, you could use a simple html output. The output would basically output the root menu’s immediate children. While displaying a menu item, the cell/div would be clickable. Its onclick would either send the user to a given URL, or execute a given script call.
In terms of setting the menu based on the current context, an interceptor requesting the desired root menu seems enough. For example, FooAction would implement MenuProvider. A MenuProvider would return its desired root menu. If FooAction wanted to modify the existing root menu, rather than completely replacing it, it would implement MenuAware. The same aforementioned interceptor would set the root menu on MenuAware classes.
Constructive suggestions appreciated.