Two Laptop Bag
The moose likes Struts and the fly likes Menu Display Problem in STRUTS .... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Menu Display Problem in STRUTS ...." Watch "Menu Display Problem in STRUTS ...." New topic

Menu Display Problem in STRUTS ....

Yogesh Mathur

Joined: Apr 18, 2002
Posts: 17
Hi All,

I am stuck with a very peculiar problem in STRUTS...

I am making a web application where the menu's are generated dynamically by loading them from database.

I have a menu table, from where I get the menu id, menu name, menu level and parent menu flag.

Menu ID is primary key (DB2 TIMESTAMP), Menu name is name of menu, menu level describes what level should the menu be displayed at. For ex: if menu level = 0, it is a top level menu. It can have its children menu with menu level = 1.
Similarly menu level 1 can have children with menu level = 2

I need to display these in order:
first the top level menu (menu level = 0)
below it its children(menu level = 1)
second level menu(menu level = 2)

another top level menu (menu level = 0)
1st level children (menu level = 1)

..... and so on ...

I am getting the list of menu's, sorted in the order they have to be displayed in a vector with the four fields as menu id, menu name, menu level & parent menu flag. Parent menu flag is to indicate weather this menu has got children or not, so that I could know that I have reached the end of a tree and have no children menu's further.

I have to iterate through this vector in my jsp page and display the menus in indented format based on their level..

Ex: Top Level Menu 1
First Level 1
First Level 2
Second Level 1

Top Level Menu 2
First Level 1
Second Level 1

.... and so on...

I have to put tabs based on the menu level, for 0 level no tab, for 1 level 1 tab, for 2 level 2 tabs .. and so on..

I need some solution as to how can I achieve this using STRUTS ....

Eagerly waiting for suggestions,

Thanks in Advance...


Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

I don't think Struts was really meant for that kind of solution.
You might be able to use logic:iterates or something, but most of what you're doing will probably require scriptlets or custom tags.

A good workman is known by his tools.
frisode jonge
Ranch Hand

Joined: Dec 30, 2003
Posts: 34
like marc says, create a custom tag.

first in your action, you call a helper which goes to the database and creates the vector (hmm, still jvm 1.1 ?). Then save the vector in the request and have the action map to a jsp page (like normal struts)

second, create a custom tag which has input of a vector and which creates html as output.

Then in the jsp page call the tag at the appropriate place and display the menu the way you want. plenty of examples around. If you need javascript have a tag that creates the javascript for you dynamically, again having a vector as input.

I agree. Here's the link:
subject: Menu Display Problem in STRUTS ....
It's not a secret anymore!