开发者

Using variables in jstl if statement

I have something like 开发者_如何学Gothis

 <c:forEach var="authority" items="#{SPRING_SECURITY_CONTEXT.authentication.principal.authorities}">

      <c:if test="${fn:contains( ${authority} , ROLE_ADMIN) }">

      </c:if>
</c:forEach>

but it does not working, any ide how can I make this? Maybe there is some other way?

//Edited


There are 2 problems:

  1. You should not nest EL expressions. Just reference the EL variable the usual way.

    <c:if test="${fn:contains(authority, ROLE_ADMIN)}">
    
  2. It's not clear from the question context if ROLE_ADMIN is already in the EL scope. But you need to know that you cannot reference constants in EL. If it's for example an enum, then it's good to know that they are just evaluated as String. You need to quote it then.

    <c:if test="${fn:contains(authority, 'ROLE_ADMIN')}">
    


You're missing a closing ")" in your if test:

 <c:forEach var="authority" items="#{SPRING_SECURITY_CONTEXT.authentication.principal.authorities}">

      <c:if test="${fn:contains( {$authority} , ROLE_ADMIN ) }">

      </c:if>
</c:forEach>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜