JSTL if-statement inside HTML-attribute

Mickel picture Mickel · Oct 22, 2009 · Viewed 51.7k times · Source

is it possible to do something like this in JSTL:

<div class="firstclass<c:if test='true'> someclass</c:if>">
   <p>some other stuff...</p>
</div>

Is there any way to get this to work, or is there a better way to add a class by looking at a JSTL-if-statement?

Answer

runfa picture runfa · Oct 23, 2009

It's also possible to use an EL expression directly like this:

<div class="${booleanExpr ? 'cssClass' : 'otherCssClass'}">
</div>