Kleber Mota
Kleber Mota

Reputation: 9065

Get name of annotation class in the jsp page

When I add this code to my jsp page:

<c:set var="wizard" value="nope"/>
<c:forEach var="annotation" items="${command['class'].getAnnotations()}">
    ${annotation['class'].simpleName}<br/>
    <c:if test="${annotation['class'].simpleName == 'Wizard'}">
        <c:set var="wizard" value="yes"/>   
    </c:if>
</c:forEach>

I get something like Proxy96 for the name of the annotation class, instead of the real name. What I can do to this code retrieve the real name of the annotations?

Upvotes: 3

Views: 326

Answers (1)

obourgain
obourgain

Reputation: 9336

You have to use ${annotation.annotationType().name} to get the name of the annotation, instead of ${annotation.class.simpleName}. An Annotation object is just a proxy that represents that instance of the annotation on that class.

Example:

<c:forEach var="annotation" items="${yourObject.annotations}">
    Annotation: ${annotation.annotationType().name}<br/>
</c:forEach>

Upvotes: 1

Related Questions