I'm starting out a Spring MVC 3.0 application and getting controllers and views working nicely, the one thing I now need to do is get navigation working. So for each view I have, it needs to know what item in the "menu" part of the view to highlight and what menu options are available to that view.
One thing I thought of was to get the controller to tell the view where it is, but that's binding view logic into the controller. My views menu is in its own include which I include within each view.
What are your approaches? I'm thinking of using tiles, to this point I've only been using JSP and JSTL, maybe this will help?
The @RequestMapping annotation can be applied to class-level and/or method-level in a controller. The class-level annotation maps a specific request path or pattern onto a controller. You can then apply additional method-level annotations to make mappings more specific to handler methods.
Spring MVC Framework follows the Model-View-Controller design pattern. It is used to develop web applications. It works around DispatcherServlet. DispatcherServlet handles all the HTTP requests and responses.
Spring WebFlux is the new module, it's an alternative to spring-webmvc module and built on reactive framework. This module is used to create fully asynchronous and non-blocking application built on event-loop execution model.
I recommend you to use tiles as a view manager, and a viewNameTranslator like this:
<bean id="viewNameTranslator" class="org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator">
<property name="separator" value="." />
</bean>
So this way you can avoid specifing view names on controller class returning void.
later on tile-def.xml you define a view somethin like this:
<definition name="newView" extends="baseView">
<put name="menu" value="/pages/menu/menu.jsp?highlightedView=newView" />
<put name="body" value="/pages/newStuff/content.jsp" />
</definition>
This way menu.jsp receives an aditional parameter highlightedView with the info you need.-
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With