my dog learned polymorphism*
The moose likes Struts and the fly likes where and who should create site-global stuff like navigatonal menu? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "where and who should create site-global stuff like navigatonal menu?" Watch "where and who should create site-global stuff like navigatonal menu?" New topic
Author

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

Raigedas Lietuvis
Greenhorn

Joined: Oct 31, 2009
Posts: 16
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.


    regards,
    Raigedas
    Prakash Mani - Attur
    Ranch Hand

    Joined: Oct 08, 2009
    Posts: 100
    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

    Joined: Oct 31, 2009
    Posts: 16
    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

    Joined: Sep 29, 2008
    Posts: 12617

    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

    Joined: May 05, 2010
    Posts: 213


    I agree with David. Where, when, how you retrieve or store the data depends on what makes the most sense for your application.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: where and who should create site-global stuff like navigatonal menu?