I have an Item object, which has a field that is a Set of ItemTypes:
public class Item {
EnumSet<ItemType> itemTypeSet;
...
public Set<ItemType> getItemTypeSet(){
return this.itemTypeSet;
}
}
ItemType is of course a simple Enum.
public Enum ItemType {
BOLD, THIN, COOL, ROUND;
}
In my JSP I would like to use JSTL to see if an item has a specific ItemType, I tried to use the following three snippets but I get no errors and no results. I'm not sure why all 3 are failing. Could somebody explain, for each of these 3 cases, why the program doesn't work like I think it does, and provide a 4th alternative that's working :)?
<c:if test="${item.itemTypeSet.contains('BOLD')}">
Method 1 works!
</c:if>
<c:if test="${item.itemTypeSet.contains(ItemType.valueOf('BOLD'))}">
Method 2 works!
</c:if>
<c:if test="${item.itemTypeSet.contains(ItemType.BOLD)}">
Method 3 works!
</c:if>
Important is that the ItemType
enum is public and not inside another class. It is totally accessible for any other class, including the ones that resolve the EL/JSTL/JSP.
Note that iterating over all values in the enumset works fine:
<c:forEach items="${item.itemTypeSet}" var="itemType">
<p>${itemType}</p>
</c:forEach>
gives as result:
BOLD
ROUND