Reputation: 1879
I'm trying to send a parameter in the script tag like this:
<script th:src="@{/js/myScript.js(arg0=${value})}"></script>
Where value is the result for: hasAuthority('USER')
So, I tried this:
<script th:src="@{/js/myScript.js(arg0=${hasAuthority('USER')})}"></script>
But this doesn't work:
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "hasAuthority('USER')" (template: "groups" - line 61, col 9)
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1004E: Method call: Method hasAuthority(java.lang.String) cannot be found on org.thymeleaf.spring4.expression.SPELContextMapWrapper type
I've used this function before for showing divs without problems:
<li sec:authorize="${hasAuthority('ADMIN')}">
Upvotes: 0
Views: 299
Reputation: 5097
Try this.
<script sec:authorize="${hasAuthority('USER')}" th:src="@{/js/myScript.js(arg0=ADD_VALUE_HERE)}"></script>
This will only load this particular js if you have the right authority. For your case, just change the value of the js argument for whatever you need.
Upvotes: 1