Skip to main content

Dynamic menu creation

3 replies [Last post]
rafboard
Offline
Joined: 2007-08-23

Hi,

I´m making an application using jmaki accordion menu.The issue is I want to generate the menu dynamically on my jsp depending of the profile user of the application.I really don´t know the properly way to do this,the only one way i thinked is getting a hidden field in my jsp with the profile of the user and modifying the source code of the widget for creating new panes in the case of some profiles but i think is not very fair way.

I really would thank you ideas.

Bye

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
gmurray71
Offline
Joined: 2003-07-31

My suggestion would to be to load the accordion menu data using a service and use a JSP page to generate the menu based on the profile. This is pretty easy to do:

So instead of a value use a service like:

mymenu.jsp could then generate the menu in accordance with :

http://wiki.java.net/bin/view/Projects/jMakiMenuDataModel

Basically you can do your initial test by cutting the default value out of the widget:

{menu : [
{label: 'Links',
menu: [
{ label : 'Sun.com',
href : 'http://www.sun.com'},
{ label : 'jMaki.com',
href : 'http://www.jmaki.com'}
]
},
{label: 'Actions',
menu: [
{ label : 'Select',
action :{topic: '/foo/select',
message: { targetId : 'bar'}}
},
{ label :'Set Content',
action :{topic: '/foo/setContent',
message: { value : 'test.jsp'}}
}
]}
]
}

and put it in the mymenu.jsp

Once you have that working then you can then use scriptlets to generate different portions depending on the profile. One thing to look out for is to use proper JSON format. Trailing commas for example will cause problems with IE.

Let us know if you need further help.

rafboard
Offline
Joined: 2007-08-23

I understand what you mean,but I still have the same problem, I don´t really know how to generate json code in a jsp file.Maybe i´m a bit clumsy but i would thank you very much an example of generating this json code dynamically in a jsp page.

gmurray71
Offline
Joined: 2003-07-31

Hi,

First of all you will need to update your accordionMenu widget. You can do this by copying the file located at:

https://widgets.dev.java.net/source/browse/*checkout*/widgets/trunk/code...

To your web application /resources/jmaki/accordionMenu directory.

Next create a JSP page called menu.jsp and paste in the following contents:

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%
request.setAttribute("category", request.getParameter("id"));
%>

{menu : [
{label: 'Links',
menu: [
{ label : 'Sun.com',
href : 'http://www.sun.com'},
{ label : 'jMaki.com',
href : 'http://www.jmaki.com'}
]
},
{label: 'More Links',
menu: [
{ label : 'Java.com',
href : 'http://java.sun.com'},
{ label : 'Ajaxian',
href : 'http://www.ajaxian.com'}
]
}


,
{label: 'Books',
menu: [
{ label : 'Book 1'},
{ label : 'Book 2'},
{ label : 'Book 3'}
]}


,
{label: 'Music',
menu: [
{ label : 'Genre 1'},
{ label : 'Genre 2'},
{ label : 'Genre 3'}
]}

]
}

If you modify this file make sure that you don't have any extra commas (malformed JSON) they will cause IE to throw an error message.

Next in your page you can access different variations of the widget by using including an "id" parameter as books or music:

service="menu.jsp?id=books" />

Gives you an accordion with a Books pane and

service="menu.jsp?id=music" />

That's it. You should have some customizable menus now. Let me know if this doesn't work for you.

-Greg