2011-07-06 138 views
1

我有这样的事情使用变量if语句

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

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

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

,但它不工作,任何IDE我怎样才能使这个?也许还有其他的方式?

//编辑

你如果测试

回答

0

你缺少一个右 “)”:

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

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

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

这不是一个问题,一个刚刚misstyped –

1

有2个问题:

  1. 你不应该巢EL表达式。只需引用EL变量即可。

    <c:if test="${fn:contains(authority, ROLE_ADMIN)}"> 
    
  2. 它不是从问题方面清楚,如果ROLE_ADMIN已经在EL范围。但是你需要知道你不能在EL中引用常量。如果它是例如enum,那么很高兴知道它们仅被评估为String。你需要引用它。

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