Announcement Announcement Module
No announcement yet.
Advice on Controller-driven menu... Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Advice on Controller-driven menu...

    I am looking for some advice on how to handle adding dynamic content to the menu.jspx. Basically, what I want to do is populate part stuff in the left menu (drawn with menu.jspx) from my Entities.

    The problem isn't how to do, it's how to do it the best way. The way I see it, I have 3 options:
    1. I could use dojo and JSON to draw in the menus. I do this now, but its slow
    2. Put a block of code in EVERY Controller handler method to populate the data into the ModelMap, then use server-side JSP code to build the menu. This seems like a code-maintenance nightmare
    3. Use a point cut (Aspect) to auto-attach to all the controller method, which would do the above (seems better, but thats a lot of layers of AspectJ)

    Whats the most common pattern? Are there others that I haven't thought of?

    Thanks in advance.

  • #2
    Does anyone not have any input on this? I am not looking for solutions, only the most common patterns. I would settle for a "Go read this book" answer.


    • #3
      It is hard to come up with an specific answer to your question...
      Since there are not details on what exactly you are doing.

      I think your solution is good, but since you are populating with stuff coming from the entities you always would have to add up the back end plus the client-server round trip times. You are already using JSON so you have the round trip timing covered. Try to speed up the access to db stuff.

      Just on the side. I posted an blog article on a different type of dynamic menus. It is at

      I hope it helps you



      • #4
        Thanks for the reply. I find the hardest thing to grasp when dealing with new frameworks/languages/tools is learning the proper pattern. Last year I dove into Objective C and Xcode, and coming from Java my code was a mess. It took almost a year to get my first project out, not because it wasn't working, but because I made so many bad decisions in the beginning that changes later on were tough. I ended up just scrapping the original code, starting a completely new project, and copy/pasting bits of the old code into the proper places. Once I did that, things not only worked 100% better, but even complicated changes were easy and made tons more sense.

        So, a little back ground: I am working on a photo gallery site as a learning project. The galleries will be listed on the left side, where the Spring-generated menu is. I have a DIV tag defined in menu.jspx which is empty. I then set up the appropriate Dojo code to look up the root galleries and add them. When a user clicks one of the root categories, the children are then loaded and added. There is some fancy "Loading..." things happening as the JSON call is made, but that's just fluff and not really relavent. The problem I am running into is that this is slow (keep in mind I am on my laptop, which is a first-gen MacBook Pro, so not really speedy in any sense).

        I guess the minimal thing I need to do is modify the code I have to get all the possible menus up-front. Right now, its getting the root menus, then retrieving the children one you click. This means multiple round-trips and is making the experience worse. I just didn't want to keep beating this dead horse if there was a better way to do things.

        The other thought, as mentioned, I had was to do it all in the JSPs directly, meaning just shove them in while the JSP is built instead of making a separate call to the backend. The problem there is I really need to have the menus put together on all the pages, so I would have to remember on every single Controller method to get a list of possible menus and shove them into the Model so they are accessible from the JSP.

        I guess one more option would be to try to access the gallery Entities directly in the menu.jspx. What I mean there is, instead of populating the entities into a model in the Controller(s), just call the Gallery.findXXX() and build the menu using raw JSP code. This way I dont need to worry about copying code all over and making sure its in-sync.

        Anyway, I will definitely check out your blog post first, though.

        Thanks again!
        Last edited by mbabauer; Nov 9th, 2011, 05:48 PM.