File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generate Menu from Database.

 
Paddu Hegde
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to generate dynamic menu according to the user roles. This i want to achieve with JSP.

Currently i have a javascript for menu design and effects. I want the following steps done which is pending :

1.Create a Menu entries into a database
2.Render menu items from database
3.Have one field as "role" employee and customer. Now based on customer or employee the menus should be displayed.

Kindly suggest me how to go about this. It would be great if a sample code shared.

Thanks a lot for your help.

Thanks and Rgds,
Kino
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Paddu xdd", please check your private messages for an important administrative matter.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What code have you written so far? What has you stumped?
 
Paddu Hegde
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
What code have you written so far? What has you stumped?


I have completed javascript coding for menu design only. In JSP how to go about is a big question mark for me now!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the menu is working, what do you need to do in the JSP? Are there dynamic parts of the menu that need to be filled in before sending the HTML page to the browser?

Remember that JSP is just a templating mechanism to dynamically generate the HTML page sent to the client. So while JSP can help you create the HTML and JavaScript that implements the menu, the structure and behavior of the menu is still controlled by HTML and JavaScript.

So once you have the HTML and JavaScript for the menu settled (which it sounds like you already have), it simply a matter for using the JSP mechanisms to fill in the dynamic parts that can;t be ahrd-coded in advance.
 
Paddu Hegde
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
If the menu is working, what do you need to do in the JSP? Are there dynamic parts of the menu that need to be filled in before sending the HTML page to the browser?

Remember that JSP is just a templating mechanism to dynamically generate the HTML page sent to the client. So while JSP can help you create the HTML and JavaScript that implements the menu, the structure and behavior of the menu is still controlled by HTML and JavaScript.

So once you have the HTML and JavaScript for the menu settled (which it sounds like you already have), it simply a matter for using the JSP mechanisms to fill in the dynamic parts that can;t be ahrd-coded in advance.



Hi Again,

JSP is pretty new to me. Since my project needs that i use JSP, i have come to this forum ;-)

yes you are right javascript is pefectly working for me. My question here now is how to impplement in such a way that the menu items from Database is used by javascript from JSP connection?

I would appreciate a code sample.

Thanks and Rgds,
Pradeep
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would use JSP mechanisms to take the information from the database (but under no circumstances should you do DB access in the JSP itself -- delegate that to a model class) and include it in the HTML markup.

If you are new to JSP, I'd suggest working through a JSP tutorial (make sure that it's up-to-date, concentrating on JSTL and EL, and not putting Java code in the JSP) to familiarize yourself with JSP technology.

Also, read these articles from the JavaRanch Journal:

The Secret Life of JavaServer Pages
The Front Man
[ September 01, 2008: Message edited by: Bear Bibeault ]
 
Karthik Rajendiran
Ranch Hand
Posts: 217
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Role Based Menu?

Suggestions,
Suppose if you are using any struts framework or if you have any welcome page or particular url pattern,

1. write a filter named RoleMenuFilter,which should get invoked for all the url patterns
2. it should get the user details from session or request and
scan db for its role and menu for this role.

Rolemaster table has roles
Menu master table would have menus and linked roles

MENU MASTER
ID, MENUNAME, MENUDISPLAYNAME, MENU URL, PARENTMENU
parentmenu field is optional, if you are not going for nested menus

ROLES MASTER
ROLEID, ROLENAME

ROLES_MENU [joining table]
ROLE_ID, MENU_ID
foreign keys to above master tables

Now scan these tables to get list of menus for this user and keep it in request attribute.


now while displaying the naviagation portion

<c:forEach var="menuItem" items=${menuList}>
you can dislay menuItem.DisplayName, menuItem.Url
</c:forEach>

Hope it helps
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the OP didn't say he was using Struts, and did not say that menu was user-specific. But if so, I would not use the filter approach. That incurs unnecessary overhead on each request. And what are the chances that the menu information needs to be known for each and every request? Rather, I'd set up any role-specific information in the session once at authentication time.
 
Paddu Hegde
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
Well, the OP didn't say he was using Struts, and did not say that menu was user-specific. But if so, I would not use the filter approach. That incurs unnecessary overhead on each request. And what are the chances that the menu information needs to be known for each and every request? Rather, I'd set up any role-specific information in the session once at authentication time.


Hi Bear, Hi All,

Thanks for your tips..

Now i am able to retrieve all the data from database through java.

Now my next step is to pass this data to a html page. Any idea?

Thanks and Rgds,
Pradeep
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic