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