1

this might be a strange question but i couldn't find any hints, ideas, howto's, whatever on this topic. Im searching for ideas or approaches to control my frontend navigation/menu in a spring based webapp.

Im using the latest Spring MVC framework with Sitemesh and JSP.

This is how i am implementing it at the moment:

The user clicks on a element in the frontend navigation ==> Request is sent and handled by my spring controller ==> now im setting a request attribute ==> next checking in my JSP if there is something to highlight in the navigation/menu.

I can see many disadvantages of this approach as i need to handle this always manually in my controller actions and jsps plus to this it feels somehow really overloaded as this is the way i have seen in good old struts webapps 10 years ago...

Does anybody have any ideas how to implement a clean and straight forward navigation strategy?

StephanM
  • 1,350
  • 2
  • 24
  • 50
  • Maybe you are looking for this http://stackoverflow.com/questions/29090248/how-to-add-breadcrumb-to-spring-mvc or this https://github.com/pawanspace/BreadCrumb-Spring-MVC – clbcabral Aug 11 '15 at 13:55

1 Answers1

1

This is what I did in my SiteMesh decorator:

<c:set var="path" value="${requestScope['javax.servlet.forward.request_uri']}"/>

Later, in the menu...

<li class="${fn:startsWith(path, '/somePath')?' active':''}">
  <a href="<c:url value='/somePath/whatever'/>">Some Path</a>
</li>
Neil McGuigan
  • 46,580
  • 12
  • 123
  • 152
  • I like this approach more than what im using at the moment. At least you dont need to handle request attributes like i do at the moment. But still error-prone imho in the case of refactoring controller/action names. Also a bit dangerous if you use i18n uris (what im not planning). But thx for the idea! With the feedback i got so far it looks at the moment like there are not really some common strategies / best practices out there... – StephanM Aug 12 '15 at 05:34