Play Framework: How do I change active class on route change

I am using Play Framework 2 for Java and Bootstrap Helper in my project and I want to apply active class on sidebar link click. I am using side nav bar for navigation and by default one link is always has active class on page load, so thats why in every time only one link is highlighted as a active link, but how to change the class="active" on route or link change, is there any way to check the route path is our html scala template file.

Here are my side bar navigation code.

<ul class="nav nav-list">
     <li class="active"><a href="/menu1">Menu1</a></li>
     <li><a href="/menu2">Menu2</a></li>
     <li><a href="/menu3">Menu3</a></li>
</ul>

Here are my routes file

GET    /menu1          com.demo.project.controllers.DemoController.menu1()
GET    /menu2          com.demo.project.controllers.DemoController.menu2()
GET    /menu3          com.demo.project.controllers.DemoController.menu3()

Please give me some suggestion on it!

Answers


Finally I got solution for my problem, I am sharing my solution for others too. Firstly I created a method inside my html scala template file.

@activeLink(currentPath:String) = @{
if(request.path.equals(currentPath)) "active"
}

Now need to call the above method inside class attribute of anchor tag.

<ul class="nav nav-list">
 <li class="@activeLink("/menu1")"><a href="/menu1">Menu1</a></li>
 <li class="@activeLink("/menu2")"><a href="/menu2">Menu2</a></li>
 <li class="@activeLink("/menu3")"><a href="/menu3">Menu3</a></li>
</ul>

Here is my final solution, If some one has another solution or approaching different way for the same so please share those also.


Need Your Help

Best way in Java to write a file direct to a remote system via scp and sftp

java sftp scp jsch

So in my Java client I'll be creating a new file, and I want this written direct to the remote system via scp or sftp (user can select which) - I do not want the file written to the local file system

Why does my SplashScreen Not show a Label (Text)

c# winforms splash-screen

I have a WinForm called SpalshScreen.cs with a simple label with the Text property is set to "Data Loading...". The label is centered in the Form. I also have a public method called DoClose() method