Reputation: 3409
I am trying to get the request params in thymeleaf code using param
variable. Here is the documentation for param: https://www.thymeleaf.org/doc/tutorials/3.1/usingthymeleaf.html#web-context-namespaces-for-requestsession-attributes-etc..
So I have written this code:
<a th:if="${#maps.containsKey(param, 'location')}" th:href="@{my_endpoint(pageNo=${i},location=${param.location})}" th:text="${i}"
class="Some classes">stat+1</a>
The problem is, containsKey()
finds the string location
always, even if it's not there.
For the debugging purpose I have written all the keys. I have taken a random string ('kjkakajkdkdkhaha-1') that is not in these keys in UI but when checking if this random string key exists, it returns true. I've shared my debug code below:
<div th:each="map : ${param.keySet()}">
<p th:text="' key ' + ${map}"></p>
</div>
<div th:if="${param.containsKey('kjkakajkdkdkhaha-1')}">
<p th:text="'kjkakajkdkdkhaha-1 key check ' + ${#bools.isTrue((param.containsKey('kjkakajkdkdkhaha-1')))}"></p>
<p th:text="'kjkakajkdkdkhaha-1 key check ' + ${param.containsKey('kjkakajkdkdkhaha-1')}"></p>
<p th:text="'kjkakajkdkdkhaha-1 key check ' + ${#maps.containsKey(param, 'kjkakajkdkdkhaha-1')}"></p>
</div>
I tried above these 3 checking but all are returning true, which shouldn't. My question is, why is it returning true always?
Here are the elements from inspect mode of chrome:
<div>
<p> key name</p>
</div>
<div>
<p> key continue</p>
</div>
<div>
<p>kjkakajkdkdkhaha-1 key check true</p>
<p>kjkakajkdkdkhaha-1 key check true</p>
<p>kjkakajkdkdkhaha-1 key check true</p>
</div>
So, in above code, available keys are name and continue. But I'm getting true, even if kjkakajkdkdkhaha-1
is looked up by containskey()
.
Upvotes: 1
Views: 46