Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:17
Conditional display of menu and/or menu item
Poster: blackettg
Dated: Tuesday January 17 2006 - 16:45:23 GMT
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?
Poster: Ruth
Dated: Tuesday January 17 2006 - 21:36:53 GMT
Hi,
Try this topic and see if it helps.
http://www.milonic.com/forum/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
Poster: kevin3442
Dated: Wednesday January 18 2006 - 1:37:38 GMT
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:
<% 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";);
}
<% } %>
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