Monday, April 15, 2013

EL - JSTL samples


Suppose you want to select the first element of a List to print it. Easy
 <c:out value="${myList[0]}" />  
It can get complicated if you have not a list but a map, with numeric keys - see here.

What about comparing strings :
 <c:if test = "${user.role == 'ADMIN'}">  
Comparing the above two for selecting an option in a drop down :
 <option value="${role}" ${role == selectedRole ? 'selected' : ''}>${role}</option>  
Notice this wont work with xhtml. See here for escaping quotes.


TBC

Posted2013.04.15 13.23 UTC