Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Raigedas Lietuvis
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.
     
    Prakash Mani - Attur
    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
     
    David Newton
    Author
    Rancher
    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.
     
    Richard Golebiowski
    Ranch Hand
    Posts: 213
    Eclipse IDE Java Tomcat Server
    • 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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic