0

I have a context path /userlist and using server side pagination which results in URI like this: http://localhost:8080/userlist/?pageSize=10&page=2. I am trying to append class to this tag using Thymeleaf dynamically.

<li class="nav-item">
    <a class="nav-link" th:with="urls=${new String[]{'/userlist','/userlist/*'}}"
        th:classappend="${#arrays.contains(urls, #httpServletRequest.getRequestURI()) ? 'active' : ''}" href="/userlist"
        th:href="@{/userlist}">
        <span class="nav-icon">
            <i class="fas fa-users"></i>
        </span>
        <span class="nav-link-text"> Manage Users</span>
    </a>
</li>

Above works perfectly fine for userlist only. But not for http://localhost:8080/userlist/?pageSize=10&page=2.

Question: What I am missing here?

Ajay Kumar
  • 2,906
  • 3
  • 23
  • 46
  • `#arrays.contains` only matches strings... it's doesn't have special functionality for wildcard characters like `*`. (Is that what you're expecting to happen when searching the string `'/userlist/*'`?) – Metroids Feb 22 '22 at 16:33
  • Yes... something like that. – Ajay Kumar Feb 22 '22 at 17:37
  • But wondering if I have condition for `contains` why it is not working by using `/userlist` alone? – Ajay Kumar Feb 22 '22 at 18:02

0 Answers0