• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

where and who should create site-global stuff like navigatonal menu?

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please share, what is the best practice (or just how you do that) to place same stuff on every page. lets say we are building an e-shop. on every page there must be a product menu whichs is actualy a list of categories stored in DB. i can think of these ways to implement the scenario.
who should create:
  • create AbstractAction, a base for other action to extends. that AbstractAction should check if menu has already been built, and should build it if not
  • an Interceptor should check if menu has already been built, and should build it if not

  • where to store created menu:
  • in Session
  • create a Singleton for a menu


  • please point me to correct dirrection.
     
    Ranch Hand
    Posts: 100
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    create a single menu file(for example nav-menu.jsp)....use separate config files for each module.. use tiles to insert menu files in all the modules..set the module name in session scope..use if else condition in the jsp page to highlight the current module by getting the module name from the session...

    Is this the one you have asked or some other? Because most of the times i do not the questions properly...
     
    Raigedas Lietuvis
    Greenhorn
    Posts: 16
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    i understand how to display menu for the user. what i am asking is: where should occur the retrieval of the menu data (model, entities) from database? yes, we could build DAOs and then even Facade (or call it ServiceObject). but where and who should check if the menu is already retrieved (we should not query database on every page request because it is expensive operation and the menu data will be the same) and stored in session map, or should be retrieved yet? is it logical to create an interceptor for that? or place this in AbstractAction code? currently i have implemented this with interceptor like this:


    but my concern is - maybe interceptors is not the best choise here? maybe interceptors should be used for more crosscutting Aspect-Oriented stuff like logging, authentication?

    thank you
     
    Author
    Posts: 12617
    IntelliJ IDE Ruby
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Personally, I don't think I'd use an interceptor for this--but that doesn't mean it's a *bad* idea.

    If the menu only has to exist after a user logs in, I'd attach the load to the login process somehow. If it has to appear no matter what, then I'm not as sure; I'd probably put it in a base action class and lazy-load it when it's first required. On the other hand, having it in an interceptor keeps the action class cleaner--so I don't really have a good technical argument for why I'd do it that way.
     
    Ranch Hand
    Posts: 213
    Eclipse IDE Tomcat Server Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    I agree with David. Where, when, how you retrieve or store the data depends on what makes the most sense for your application.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!