Conditional display of menu and/or menu item

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
blackettg
Beginner
Beginner
Posts: 1
Joined: Tue Jan 17, 2006 5:38 pm

Conditional display of menu and/or menu item

Post by blackettg »

I am trying evaluating the menu system, so far I like it very much. However, I am having trouble conditionally displaying menus.

We are developing a struts app and have several privs that reside on the session that determine what the user gets to see and do. Based on these privs I need to display, or not display, certain menus or in some cases certain menu items.

How can I do this using your menu system?
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Post by Ruth »

Hi,

Try this topic and see if it helps.

viewtopic. ... 6346#26346

It talks about changing the menu or menu item depending on page viewed but may be applicable to what you want.

Ruth
User avatar
kevin3442
Milonic God
Milonic God
Posts: 2460
Joined: Sat Sep 07, 2002 12:09 am
Location: Lincoln, NE
Contact:

Post by kevin3442 »

Well... maybe one of the other forum denizens has some ideas. I know next to nothing about developing struts, but I'll give it a shot.

From what little I've seen in passing, seems to me struts apps use JSP as the scripting language, no? If so, I guess the same logic would apply as does when using asp, php, or any other server-side scripting language. You could load your menu_data file into the page using a javascript <script> tag, but rename menu_data.js to menu_data.jsp, so that it passes through the jsp parser when it's served. That way, you could mix straight javascript code with jsp code... use jsp conditionals to decide what javascript (i.e., what menu code) will be served and what won't.

I don't know the exact syntax of jsp conditionals or how to access session values etc., so please forgive the coding sins I'm about to commit. But I'm talking about something like this:

menu_data.jsp

Code: Select all

<% if (whatever.the.test.is) { %>
  with(milonic=new menuname("menuname")){
    style=menuStyle;
    orientation="vertical";
    aI("text=item1;url=whatever1.htm";);
     .
     .
     .
    aI("text=itemN;url=whateverN.htm";);
  }
<% } else { %>
  with(milonic=new menuname("menuname")){
    style=menuStyle;
    orientation="vertical";
    aI("text=differnetItem1;url=whatever1.htm";);
     .
     .
     .
    aI("text=differentItemN;url=whateverN.htm";);
  }
<% } %>
That sort of logic, with the conditionals wrapped around the entire menu definition, would generate one of two possible menus, using the same menu name, depending on the outcome of the conditional test. You could use the same logic to generate a menu or not generate one at all.

Same idea applies to conditionally-generated menu items; just wrap the conditional jsp tests around each aI() item.

I suppose you could use jsp switch statements too, depending on whay type of conditions you need to test.

So... I totally don't know if I answered your question, but maybe that answers somebody's question out there! ;)

Cheers,

Kevin
Post Reply