How would you correctly list objects in jsp with different types? Say, for example, I have to display these different objects in that order.
One way could be to use a generic type or instance variable, but that means having a large switch / if statement to manage them:
<c:forEach var="o" items="${bigListofObjects}" >
<c:choose>
<c:when test='${o.type=="simple"}' >
</c:when>
<c:when test='${o.type=="complex"}' >
</c:when>
</c:choose>
</c:forEach>
I could add a render () method for each class, but then that means mixing the view with the rest of the code.
What happens if I want to make another type later? Is there something I can do with custom jsp tags?
source
share