This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Best practice for menus inclusion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Best practice for menus inclusion" Watch "Best practice for menus inclusion" New topic
Author

Best practice for menus inclusion

Miltos Tereres
Ranch Hand

Joined: Sep 04, 2009
Posts: 32
Hello.. I am trying to learn struts 2.1.6..
I am trying to figure how to properly include some menus....

I would liked to post an image with my menu but i may get banned because menu has non english characters.

The problem is that i think that the best practice is to use s:action to include my menu...Why ? Because i want to load the menu dynamically from an xml file and show items according to the user rights!!

s:include doesnt help cause i should use jstl and jsp and i think that it would be a mess.
Any ideas how to make my menus :S?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

i may get banned because menu has non english characters


What makes you think that?? I'm sure your account will not be closed for something like that.

s:include doesnt help cause i should use jstl and jsp and i think that it would be a mess.


You can call any resource using the s:include tag, it can be a JSP or servlet etc. Anyways, you can do this using s:action easily. You can call an action which will read the XML file (or whatever the processing logic is), then it will use a result JSP page which will display the menu. This can also be achieved if you include a servlet which will read the xml file and dispatch the request (include) to a JSP which will display the menu...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Miltos Tereres
Ranch Hand

Joined: Sep 04, 2009
Posts: 32
What makes you think that?? I'm sure your account will not be closed for something like that.

I have posted an xml file which had a few words only in non latin characters and i got a warning.
I know it doesnt make sense.

Well because i have to use that Struts i think that i should use s:action...
IS reading an xml file for every request overkill?
Because i am afraid that is i am thinking to create a singleton MenuProvider class which will load all the menus at the time of the instantiation...
Then i will call the method MenuProvider.getMenus(user) and will return a custom menu for the specified user.. I would store that menu at the session and then the jsp thing will draw the menu according the object in the session.

Is this a good practice ?
Thanks...
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

If your xml file will not change, then you can read the file and store its data in ServletContext as an attribute. That way your action won't have to read the file over and over again. Storing the actual code for the menu might not be a good idea (no reason for that, but storing HTML in session doesn't looks good to me personally)...
Miltos Tereres
Ranch Hand

Joined: Sep 04, 2009
Posts: 32
It wont change dynamically.
ServletContext is the same as application scope ?
Actually i didnt mean to store html..
It would return a List<Menu> and every menu object will have a collection of submenus...And the jsp would draw the menus.
a submenu will be an object also because there many things to include like (required rights to display,name,action-link,icon path etc)..
 
wood burning stoves
 
subject: Best practice for menus inclusion
 
Similar Threads
FBNS: Need to provide menu- and toolbar items for all actions ?
Passed! 378/400
Dynamic Menus
JMenuBar
Passed! 378/400