Reputation: 7576
I have a list of domain objects in GSP view and would like to check if any of them are of particular type:
Class Equipment {}
Class Loader extends Equipment {}
... in view:
<g:each in="${Equipment.list()}" var="e">
... check if e is a Loader....
</g:each>
I'm trying to do the check if a GSP fragment to build a nav menu and wonder if this even the right spot to do the check in.
Upvotes: 2
Views: 1739
Reputation: 7371
You can try:
<g:each in="${Equipment.list()}" var="e">
<g:if test="${e instanceof your.package.Loader}">Do anything</g:if>
</g:each>
Upvotes: 5
Reputation: 75671
If you're making the logic in a GSP complex like that you should consider creating a taglib instead. It'll be easy to test too - GSPs need to be tested with functional tests and a running web server, but you can test taglibs with integration tests.
Upvotes: 9