I am using java, spring mvc and apache tiles in my web application.
I have a layout.jsp and inside I have:
<ul class="section">
<li class="active"><a href="/search.html">search</a></li>
<li><a href="/post.html">post</a></li>
<li><a href="/contact.html">contact</a></li>
<li class="last" ><a href="/about.html">about</a></li>
</ul>
Which means that in every page I have this ul list.
Assuming the current page is “search.html”, then I need the first li to get the class “active”.
Assuming the current page is “post.html”, then I need the second li to get the class “active”.
And so on.
When clicking on post link for example, I have the controller:
@RequestMapping("/post")
public String showPostPage(Model model) {
return "post";
}
and in my tiles definition, I have the view “post”:
<definition name="post" extends="base.definition">
<put-attribute name="title" value="add post"/>
....
....
</definition>
How can I signal the view to which li it should assign the “active” class?
What is the best way to do it?
I guess you can put a model attribute in the controller and then check it in the view: