In JSP, is there a way to set the class of the iteration variable of a c:forEach
?
What I mean is, say I want to iterate over an array of com.acme.Item
, but I wish my IDE to know the class, so it can provide me with code completion, error detection etc. In jsp:useBean
I would do something like
<jsp:useBean id="myItem" class="com.acme.Item" />
and any subsequent code can be checked for correct property names, etc. But with <c:foreach>
there is no class
attribute.
Is there another way to achieve this? Or is there some technical difficulty making this is impossible?
To further clarify, say my Item
class has a name
property (so it has getName
, setName
etc. )
I want that if I do something like:
<c:forEach var="item" items="${myItems}">
${item.nam}
</c:forEach>
that my IDE/Compiler will tell me I have an error (nam
instead of name
), but currently the only way I have is to run it on the server and catch the runtime-exception.