• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Calling left menu items dynamically

 
Ranch Hand
Posts: 161
1
jQuery Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to click the left side menu items , it needs to display static contents without using if else .

Say suppose, take the example of http://www.askganesha.com/ when we click any link on the left side menu, content is displayed in the body. That part i have done using struts2 action wild pattern usage. while displaying the content in jsp, i have used if else tags, but i am not satisfied with what i have done. I want to apply a design pattern such that no if else is used and something like putting these left menu items in arraylist and display.

all the left side menu items i have given one common action as hello-* using struts2. if user clicks any link on the left side menu say suppose, clicked a link name health, then action will be hello-health.do and with the help of struts2 i can able to retrieve the health . Similarly if the user clicks on the link called wealth, then the action will be hello-wealth and i can able to retrieve the id wealth. Now like that if 20 items are there on the left menu then based on the id (like health or wealth) , i am using if(health) display health info, else if (wealth) display wealth info.

Which pattern i need to use to pick the left menu item dynamically ?


thanks & regards

swapna
 
Ranch Hand
Posts: 93
Python Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not very much clear about your queries but we did something like this. We used Struts 2 with Tiles framework.

In the Tiles template file, left side is a menu.jsp page which renders menu dynamically from an ArrayList. The ArrayList is fetched from the database and the url is written with a id or name eg. showMenu.do?menuId=10 where menuId=10 in db refers to a particular menu. Here showMenu.do is a DispatchAction which forwards/calls the tiles definition.

And on the right side, jsp pages will be loaded for each menus as defined in the Tiles definition xml file.
 
Bartender
Posts: 9625
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Swapna latha wrote:
Which pattern i need to use to pick the left menu item dynamically ?



This sounds like a Front Controller Pattern. You know, the one that Struts was designed to implement.
I would make the left menu items unique action name (hello-wealth, hello-health, etc) then map those actions in struts.xml to forward directly to a JSP since it doesn't sound like you need to use an action.
 
Swapna latha
Ranch Hand
Posts: 161
1
jQuery Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many Thanks to Joe & Karthik.

@Karthik,

I can get the list from the database and can populate as you said, but what i think is that hitting the Database is un-necessary as i have to show some static data for first two pages after that i need an action call. I too have used tiles.

What i have done in my project is all the left hand side items are directed to one of the action name say suppose astrology-*. In leftMenu.jsp what i have written is:



Struts.xml



I am using wild card pattern here. Say suppose, when client is clicking on Full Horoscope Details, then the action will be astrolgy-fullhoroscope, then i am getting the fullhoroscope in the WelcomeAction.java and using the if else condition i am displaying some static data .



What i am trying to do is to avoid database hit. But if customer clicks on the 20th left menu item, then all the 20 if-else should bypass to display some data.

@Joe

Thaks Joe for giving correct design pattern to.

thanks once again to both of you

swapna
 
Why does your bag say "bombs"? The reason I ask is that my bag says "tiny ads" and it has stuff like this:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic