Reputation: 9065
In the code below, the first loop iterate over the fields from a given class (passed to the view by the spring controller), and the second loop, iterate over the annotations of each field:
<x:Form>
<c:forEach var="item" items="${command['class'].declaredFields}" varStatus="status">
<c:forEach var="item2" items="${item.declaredAnnotations}">
<c:choose>
<c:when test="${item2['class'].simpleName == 'Checkbox'}">
<x:Checkbox/>
</c:when>
<c:when test="${item2['class'].simpleName == 'DataList'}">
<x:DataList/>
</c:when>
<c:when test="${item2['class'].simpleName == 'Input'}">
<x:Input/>
</c:when>
<c:when test="${item2['class'].simpleName == 'Radiobutton'}">
<x:Radiobutton/>
</c:when>
<c:when test="${item2['class'].simpleName == 'Select'}">
<x:Select/>
</c:when>
<c:when test="${item2['class'].simpleName == 'Textarea'}">
<x:Textarea/>
</c:when>
</c:choose>
</c:forEach>
</c:forEach>
<button type="submit" class="btn btn-default">Enviar</button>
</x:Form>
My problem is I can't be able to get the real name for the annotations. the result for item2[class].simpleName
was something like $Proxy55
(the numbers vary).
Anyone know how I can get the real name for the annotations?
Upvotes: 0
Views: 99
Reputation: 2230
You're working with java.lang.annotation.Annotation
. When you call getClass()
on an Annotation
, you'll get a proxy. You need to call annotationType()
instead.
Change item2[class].simpleName
to item2.annotationType().simpleName
.
Upvotes: 1