> I saw your message regarding the menu component and have downloaded it
from
> Ted Husted's site.  I think this would be a valuable addition to Struts.

I hope so.   ;)

> I'm working on a project where we'll need various menus dynamically
> generated based on user permissions.  I'm thinking this is possible with
> your menu component?
> I've read through you README and have looked at some of the code.  I
gather
> that I could do this by implementing my own menudisplayer?
>
Yes, this is generally what you would do.  You just implement a
MenuDisplayer, put an entry for it in the menu-config.xml file like:

    <Displayer  name="foo"
               type="name.of.your.menu.displayer"/>


Then use it via the tags to display your menus like this:

<menu:useMenuDisplayer name="foo">
    <menu:displayMenu  name="menu1"/>
    (etc..)
</menu:useMenuDisplayer>

And, of course, just define your menus in the xml as well.  Just look at the
example app for a template.
Note that you can just extend the MessageResourcesMenuDisplayer.  Just note
my intent for it was for internationalization.

There's additional options for this, but that's basically how you'd do it.
It'll be up to you to create a displayer that will look at user permissions.
You could probably just use one of the existing displayers as a template and
just insert your necessary code.

Hmm... this gets me thinking about the possiblilty of having some kind of
generic interface for checking permissions when displaying the menus.  For a
simple usage, the menu item in question would be either displayed or not
displayed.  That could be just a simple call with returned boolean value or
something.  Perhaps we can create some kind of permissionable menu displayer
that wouldn't change and people would just implement some kind of adapter
that would ask about the permissions?    It would be nice if people didn't
have to rewrite the displayer because they have there own custom way of
checking for permission.  I'll have to think about that a bit.

Hope this helps.

Scott


Reply via email to